-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
BugFix: Default fields do not work when passing schema as string to mergeSchemas #1121
Comments
I think this is because we should be using valueFromAstUntyped as the subfield types are just stubs. If advanced parseLiteral functioning is needed (ie the stuff besides validation done with the type argument), this should be after the merge. This would also come in handy in case the input type is changed, even if just the parseLiteral function is changed (for example if a different internal representation is used). In general, we should probably serialize from the default value using the old schema and then parse from that with the new schema. |
Fix to this is released in graphql-tools-fork v6.0.1. Please let me know how performs. |
The way it shook out, valueFromAstUntyped does not work from stub types either, so I just stored the entire ast. When recreating a schema, it serializes with the old type and parses with the new, unless it is working from a stub, in which case it calls parseLiteral |
🔈@JazminGonzalez-Rivero We recently released an alpha version of GraphQL Tools (#1308) that should fix your issue. Please update
Let us know if it solves your problem, we're counting for your feedback! :) |
Rolled into #1306 |
Notes:
If you pass your schema as a string to mergeSchemas it drops the default values.
I validated this by creating a unit test -> #1120
I have found exactly where it is failing -> https://github.com/apollographql/graphql-tools/blob/master/src/stitching/typeFromAST.ts#L186
reasoning ->
valueFromAST(node.defaultValue, type)
is returning undefined. If I replace type with the hard coded value expected (I.E.valueFromAST(node.defaultValue, GraphQLString)
in this case) then I see thedefaultValue
isFoo
as expected and the mergedSchema includes the defaults. so it seems type is not evaluated correctly... I tried printing it out to console and seeString
as expected... but I'm not super familiar withGraphQLInputType
andGraphQLInputObjectType
so this is where my investigation came to a head. it feels like it should be a quick fix for someone more familiar with the code base? help would be appreciated!Intended outcome: When passing schemas as strings to mergeSchemas I expect the result to have defaults defined in the original schemas (see draft PR above for basic example)
Actual outcome: defaults are dropped see output from test:
How to reproduce the issue: Pull down my branch and run
yarn test -g 'input object with default and raw schema'
I have added console Logs that should highlight the issueThe text was updated successfully, but these errors were encountered: