From e12d614fe1dc35bdbe534205ee48b83c32889233 Mon Sep 17 00:00:00 2001 From: HiroyukiOsaki Date: Sat, 13 Jun 2020 20:34:52 -0700 Subject: [PATCH 1/4] reproduce field selection in resolver --- examples/openapi-javascript-wiki/.meshrc.yaml | 1 + .../example-queries/sample.graphql | 9 +++++++ .../src/mesh/additional-resolvers.js | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 examples/openapi-javascript-wiki/example-queries/sample.graphql diff --git a/examples/openapi-javascript-wiki/.meshrc.yaml b/examples/openapi-javascript-wiki/.meshrc.yaml index 5c6bfb8e2caee..32628286f11b6 100644 --- a/examples/openapi-javascript-wiki/.meshrc.yaml +++ b/examples/openapi-javascript-wiki/.meshrc.yaml @@ -7,6 +7,7 @@ sources: additionalTypeDefs: | extend type Query { viewsInPastMonth(project: String!): Float! + viewsOver500K(project: String!): PageviewTops } additionalResolvers: - ./src/mesh/additional-resolvers.js diff --git a/examples/openapi-javascript-wiki/example-queries/sample.graphql b/examples/openapi-javascript-wiki/example-queries/sample.graphql new file mode 100644 index 0000000000000..d96d04b82f40a --- /dev/null +++ b/examples/openapi-javascript-wiki/example-queries/sample.graphql @@ -0,0 +1,9 @@ +query resolverFieldSelectionTest { + viewsOver500K(project: "en.wikipedia.com") { + items { + articles { + article + } + } + } +} \ No newline at end of file diff --git a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js index 27d6446d736cd..eb33977153f75 100644 --- a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js +++ b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js @@ -18,6 +18,33 @@ const resolvers = { } return items[0].views; + }, + async viewsOver500K(_, { project }, { Wiki }) { + const pageviewTops = await Wiki.api.getMetricsPageviewsTopProjectAccessYearMonthDay( + { + project: "en.wikipedia.org", + access: "all-access", + day: "31", + month: "05", + year: "2020" + }, { + fields: { + items: { + articles: { + view: true + } + } + } + }); + pageviewTops.items.forEach((item, index, array) => { + console.log(item); + array[index].articles = item.articles.filter( + element => { + return element.views >= 500000; + } + ); + }); + return pageviewTops; } } }; From c5548ee82b448a2112d57e37d9e136f0afe7e5da Mon Sep 17 00:00:00 2001 From: HiroyukiOsaki Date: Sat, 13 Jun 2020 20:59:48 -0700 Subject: [PATCH 2/4] typo --- .../openapi-javascript-wiki/src/mesh/additional-resolvers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js index eb33977153f75..4436de49c40f6 100644 --- a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js +++ b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js @@ -31,7 +31,7 @@ const resolvers = { fields: { items: { articles: { - view: true + views: true } } } From a7104b8ee54087a31fb53ae7722372d5e7f0160a Mon Sep 17 00:00:00 2001 From: HiroyukiOsaki Date: Tue, 16 Jun 2020 00:35:17 -0700 Subject: [PATCH 3/4] simple example --- examples/openapi-javascript-wiki/.meshrc.yaml | 4 ++ .../src/mesh/additional-resolvers.js | 46 +++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/examples/openapi-javascript-wiki/.meshrc.yaml b/examples/openapi-javascript-wiki/.meshrc.yaml index 32628286f11b6..9beefb270aa81 100644 --- a/examples/openapi-javascript-wiki/.meshrc.yaml +++ b/examples/openapi-javascript-wiki/.meshrc.yaml @@ -8,6 +8,10 @@ additionalTypeDefs: | extend type Query { viewsInPastMonth(project: String!): Float! viewsOver500K(project: String!): PageviewTops + viewsTop(project: String!): PageviewTops + } + extend type PageviewTops { + topViewArticleName: String } additionalResolvers: - ./src/mesh/additional-resolvers.js diff --git a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js index 4436de49c40f6..a12c3e186089a 100644 --- a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js +++ b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js @@ -19,7 +19,7 @@ const resolvers = { return items[0].views; }, - async viewsOver500K(_, { project }, { Wiki }) { + async viewsOver500K(obj, _, { Wiki }, info) { const pageviewTops = await Wiki.api.getMetricsPageviewsTopProjectAccessYearMonthDay( { project: "en.wikipedia.org", @@ -27,7 +27,7 @@ const resolvers = { day: "31", month: "05", year: "2020" - }, { + },{ fields: { items: { articles: { @@ -36,16 +36,42 @@ const resolvers = { } } }); - pageviewTops.items.forEach((item, index, array) => { - console.log(item); - array[index].articles = item.articles.filter( - element => { - return element.views >= 500000; - } - ); - }); + // pageviewTops.items.forEach((item, index, array) => { + // array[index].articles = item.articles.filter( + // element => { + // return element.views >= 500000; + // } + // ); + // }); + return pageviewTops; + }, + async viewsTop(obj, _, { Wiki }, info) { + const pageviewTops = await Wiki.api.getMetricsPageviewsTopProjectAccessYearMonthDay( + { + project: "en.wikipedia.org", + access: "all-access", + day: "31", + month: "05", + year: "2020" + }); return pageviewTops; } + }, + PageviewTops: { + topViewArticleName: { + resolve: async (obj, _, { Wiki }, info) => { + return obj.items[0].articles[0].article; + }, + selectionSet: ` + { + items { + articles { + article + } + } + } + ` + } } }; From a9f6921b3979a7abebe05adf187fbd3ec768830d Mon Sep 17 00:00:00 2001 From: HiroyukiOsaki Date: Tue, 16 Jun 2020 00:39:02 -0700 Subject: [PATCH 4/4] changed sample.graphql --- .../example-queries/sample.graphql | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/openapi-javascript-wiki/example-queries/sample.graphql b/examples/openapi-javascript-wiki/example-queries/sample.graphql index d96d04b82f40a..b729f3724f82e 100644 --- a/examples/openapi-javascript-wiki/example-queries/sample.graphql +++ b/examples/openapi-javascript-wiki/example-queries/sample.graphql @@ -1,8 +1,20 @@ query resolverFieldSelectionTest { viewsOver500K(project: "en.wikipedia.com") { + topViewArticleName items { articles { - article + views + } + } + } +} + +query resolverNoFieldSelectionTest { + viewsTop(project: "en.wikipedia.com") { + topViewArticleName + items { + articles { + views } } }