Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openapi field repro #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/openapi-javascript-wiki/.meshrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions examples/openapi-javascript-wiki/example-queries/sample.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
53 changes: 53 additions & 0 deletions examples/openapi-javascript-wiki/src/mesh/additional-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
`
}
}
};
Expand Down