-
Notifications
You must be signed in to change notification settings - Fork 86
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
fix for codegen rejecting operations that contain fragments with type conditions on interfaces #243
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
from io import StringIO | ||
from graphql import Source | ||
|
||
from sgqlc.codegen.operation import CodeGen, load_schema, ParsedSchemaName | ||
|
||
|
||
NESTED_INTERFACE_QUERY = """ | ||
query TestQuery { | ||
foo { | ||
... on Bar { | ||
barField | ||
} | ||
} | ||
} | ||
""" | ||
|
||
NESTED_INTERFACE_SCHEMA = """ | ||
{ | ||
"__schema": { | ||
"queryType": { | ||
"name": "Query" | ||
}, | ||
"mutationType": null, | ||
"subscriptionType": null, | ||
"types": [ | ||
{ | ||
"kind": "OBJECT", | ||
"name": "Query", | ||
"description": null, | ||
"fields": [ | ||
{ | ||
"name": "foo", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "INTERFACE", | ||
"name": "Foo", | ||
"ofType": null | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
} | ||
], | ||
"inputFields": null, | ||
"interfaces": [], | ||
"enumValues": null, | ||
"possibleTypes": null | ||
}, | ||
{ | ||
"kind": "INTERFACE", | ||
"name": "Foo", | ||
"description": null, | ||
"fields": [ | ||
{ | ||
"name": "fooField", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "NON_NULL", | ||
"name": null, | ||
"ofType": { | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"ofType": null | ||
} | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
} | ||
], | ||
"inputFields": null, | ||
"interfaces": [], | ||
"enumValues": null, | ||
"possibleTypes": [ | ||
{ | ||
"kind": "OBJECT", | ||
"name": "Baz", | ||
"ofType": null | ||
} | ||
] | ||
}, | ||
{ | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"description": "The `String` scalar type represents textual data", | ||
"fields": null, | ||
"inputFields": null, | ||
"interfaces": null, | ||
"enumValues": null, | ||
"possibleTypes": null | ||
}, | ||
{ | ||
"kind": "INTERFACE", | ||
"name": "Bar", | ||
"description": null, | ||
"fields": [ | ||
{ | ||
"name": "fooField", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "NON_NULL", | ||
"name": null, | ||
"ofType": { | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"ofType": null | ||
} | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
}, | ||
{ | ||
"name": "barField", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "NON_NULL", | ||
"name": null, | ||
"ofType": { | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"ofType": null | ||
} | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
} | ||
], | ||
"inputFields": null, | ||
"interfaces": [ | ||
{ | ||
"kind": "INTERFACE", | ||
"name": "Foo", | ||
"ofType": null | ||
} | ||
], | ||
"enumValues": null, | ||
"possibleTypes": [ | ||
{ | ||
"kind": "OBJECT", | ||
"name": "Baz", | ||
"ofType": null | ||
} | ||
] | ||
}, | ||
{ | ||
"kind": "OBJECT", | ||
"name": "Baz", | ||
"description": null, | ||
"fields": [ | ||
{ | ||
"name": "barField", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "NON_NULL", | ||
"name": null, | ||
"ofType": { | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"ofType": null | ||
} | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
}, | ||
{ | ||
"name": "fooField", | ||
"description": null, | ||
"args": [], | ||
"type": { | ||
"kind": "NON_NULL", | ||
"name": null, | ||
"ofType": { | ||
"kind": "SCALAR", | ||
"name": "String", | ||
"ofType": null | ||
} | ||
}, | ||
"isDeprecated": false, | ||
"deprecationReason": null | ||
} | ||
], | ||
"inputFields": null, | ||
"interfaces": [ | ||
{ | ||
"kind": "INTERFACE", | ||
"name": "Bar", | ||
"ofType": null | ||
}, | ||
{ | ||
"kind": "INTERFACE", | ||
"name": "Foo", | ||
"ofType": null | ||
} | ||
], | ||
"enumValues": null, | ||
"possibleTypes": null | ||
} | ||
] | ||
} | ||
} | ||
""" | ||
|
||
|
||
def test_operation_gen_nested_interface(): | ||
expected_generated_query = """def query_test_query(): | ||
_op = sgqlc.operation.Operation(_schema_root.query_type, name='TestQuery') | ||
_op_foo = _op.foo() | ||
_op_foo__as__Bar = _op_foo.__as__(_schema.Bar) | ||
_op_foo__as__Bar.bar_field() | ||
return _op""" | ||
result_buff = StringIO() | ||
schema_name = ParsedSchemaName.parse_schema_name('.schema') | ||
|
||
with StringIO(NESTED_INTERFACE_QUERY) as op_file, StringIO( | ||
NESTED_INTERFACE_SCHEMA | ||
) as schema_file: | ||
operation_gql = [Source(op_file.read(), 'op-gen.gql')] | ||
schema = load_schema(schema_file) | ||
gen = CodeGen( | ||
schema, | ||
schema_name, | ||
operation_gql, | ||
result_buff.write, | ||
short_names=False, | ||
) | ||
gen.write() | ||
generated_operations = result_buff.getvalue() | ||
result_buff.close() | ||
assert expected_generated_query in generated_operations |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barbieri I cut out a lot of the introspection output to try and keep the inlined resource small, namely the metadata about builtin things like the
__Schema
and__Type
types that describe what comes back in the introspection query itself and things related to directives. The test still ran fine, but do you think that may cause an issue later or do you not anticipate the codegen ever caring about that? Trying to avoid some future change suddenly breaking this test due to it having an incomplete introspection output.