diff --git a/examples/openapi-javascript-wiki/.meshrc.yaml b/examples/openapi-javascript-wiki/.meshrc.yaml index 5c6bfb8e2caee..9beefb270aa81 100644 --- a/examples/openapi-javascript-wiki/.meshrc.yaml +++ b/examples/openapi-javascript-wiki/.meshrc.yaml @@ -7,6 +7,11 @@ sources: 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/example-queries/sample.graphql b/examples/openapi-javascript-wiki/example-queries/sample.graphql new file mode 100644 index 0000000000000..b729f3724f82e --- /dev/null +++ b/examples/openapi-javascript-wiki/example-queries/sample.graphql @@ -0,0 +1,21 @@ +query resolverFieldSelectionTest { + viewsOver500K(project: "en.wikipedia.com") { + topViewArticleName + items { + articles { + views + } + } + } +} + +query resolverNoFieldSelectionTest { + viewsTop(project: "en.wikipedia.com") { + topViewArticleName + items { + articles { + views + } + } + } +} \ 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..a12c3e186089a 100644 --- a/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js +++ b/examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js @@ -18,6 +18,59 @@ const resolvers = { } return items[0].views; + }, + async viewsOver500K(obj, _, { Wiki }, info) { + const pageviewTops = await Wiki.api.getMetricsPageviewsTopProjectAccessYearMonthDay( + { + project: "en.wikipedia.org", + access: "all-access", + day: "31", + month: "05", + year: "2020" + },{ + fields: { + items: { + articles: { + views: true + } + } + } + }); + // 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 + } + } + } + ` } } };