graphql-tools
graphql-tools copied to clipboard
Enhance buildOperationNodeForField by taking default values into consideration
First of all - I would like to express my gratitude for the phenomenal work you guys are doing here!
Is your feature request related to a problem? Please describe.
I'm working on an a Project where we're building an SDK generator that parses an OAS based Schemas (with a huge set of endpoints where the parameters have default values specified whenever possible), coverts them into the GraphQL Schema and than builds and exposes the GQL queries/mutations. For exposing the queries we're using the buildOperationNodeForField function. Unfortunately even though our GQL Schema properly takes and captures default values from the OAS Schema specification, buildOperationNodeForField function ignores them when building queries/mutations, which degrade our DX significantly (for most initial use-cases where we would let our users quickly test generated operations W/O having to provide all argument values for queries/mutations if they have defaults already contained within the GQL Spec).
Describe the solution you'd like
It would be expected that if the GQL Specification Nodes already contains default values (for Queries/Mutations) they would also be taken into consideration and propagated to the output of the buildOperationNodeForField function.
Additional context
It would be expected that the output of the below buildOperationNodeForField fn call:
const document = buildOperationNodeForField({
schema: buildSchema(/* GraphQL */ `
type Query {
getAllPages(currentPage: Int = 0, pageSize: Int = 10, pageType: getAllPages_pageType = ContentPage, sort: String = "asc"): PagesList
}
enum getAllPages_pageType {
ContentPage
CategoryPage
CatalogPage
}
type PagesList {
...
}
`),
kind: 'query' as OperationTypeNode,
field: 'getAllPages',
models,
ignore: [],
})!;
would match the following:
query getAllPages_query($currentPage: Int = 0, $pageSize: Int = 10, $pageType: getAllPages_pageType = ContentPage, $sort: String = "asc") {
getAllPages(currentPage: $currentPage, pageSize: $pageSize, pageType: $pageType, sort: $sort) {
...
}
}
I would be more than happy to submit the PR for this feature.