Skip to content

Fix missing empty directives in DSL nodes #448

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

Merged
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
13 changes: 10 additions & 3 deletions gql/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ def executable_ast(self) -> OperationDefinitionNode:
selection_set=self.selection_set,
variable_definitions=self.variable_definitions.get_ast_definitions(),
**({"name": NameNode(value=self.name)} if self.name else {}),
directives=(),
)

def __repr__(self) -> str:
Expand Down Expand Up @@ -597,6 +598,7 @@ def get_ast_definitions(self) -> Tuple[VariableDefinitionNode, ...]:
default_value=None
if var.default_value is None
else ast_from_value(var.default_value, var.type),
directives=(),
)
for var in self.variables.values()
if var.type is not None # only variables used
Expand Down Expand Up @@ -818,7 +820,11 @@ def __init__(
"""
self.parent_type = parent_type
self.field = field
self.ast_field = FieldNode(name=NameNode(value=name), arguments=())
self.ast_field = FieldNode(
name=NameNode(value=name),
arguments=(),
directives=(),
)
self.dsl_type = dsl_type

log.debug(f"Creating {self!r}")
Expand Down Expand Up @@ -950,7 +956,7 @@ def __init__(

log.debug(f"Creating {self!r}")

self.ast_field = InlineFragmentNode()
self.ast_field = InlineFragmentNode(directives=())

DSLSelector.__init__(self, *fields, **fields_with_alias)

Expand Down Expand Up @@ -1018,7 +1024,7 @@ def ast_field(self) -> FragmentSpreadNode: # type: ignore
`issue #4125 of mypy <https://github.com/python/mypy/issues/4125>`_.
"""

spread_node = FragmentSpreadNode()
spread_node = FragmentSpreadNode(directives=())
spread_node.name = NameNode(value=self.name)

return spread_node
Expand Down Expand Up @@ -1067,6 +1073,7 @@ def executable_ast(self) -> FragmentDefinitionNode:
selection_set=self.selection_set,
variable_definitions=self.variable_definitions.get_ast_definitions(),
name=NameNode(value=self.name),
directives=(),
)

def __repr__(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from gql import Client
from gql.dsl import DSLFragment, DSLQuery, DSLSchema, dsl_gql

schema_str = """
type MonsterForm {
sprites: MonsterFormSprites!
}

union SpriteUnion = Sprite | CopyOf

type Query {
monster: [Monster!]!
}

type MonsterFormSprites {
actions: [SpriteUnion!]!
}

type CopyOf {
action: String!
}

type Monster {
manual(path: String!): MonsterForm
}

type Sprite {
action: String!
}
"""


def test_issue_447():

client = Client(schema=schema_str)
ds = DSLSchema(client.schema)

sprite = DSLFragment("SpriteUnionAsSprite")
sprite.on(ds.Sprite)
sprite.select(
ds.Sprite.action,
)
copy_of = DSLFragment("SpriteUnionAsCopyOf")
copy_of.on(ds.CopyOf)
copy_of.select(
ds.CopyOf.action,
)

query = ds.Query.monster.select(
ds.Monster.manual(path="").select(
ds.MonsterForm.sprites.select(
ds.MonsterFormSprites.actions.select(sprite, copy_of),
),
),
)

q = dsl_gql(sprite, copy_of, DSLQuery(query))

client.validate(q)