Use of @skip and @ignore directives with gql.dsl #479
Description
Activity
Directives are not currently supported with the dsl module.
@leszekhanusz, I was looking at the
graphql-corelibrary and it looks like the directives are now supported in directives.py and DirectiveNode is part of the AST. It's not clear to me whether incremental delivery directives like@deferand@streamare supported yet, but for directives that don't require any extra client-side work it looks like it should be possible to include them in the DSL module with the current state ofgraphql-core.Would you be open to extending the DSL module to support to entirely server-side directives like
@skip,@ignore,@include, etc?Here's a quick sketch of what this might look from based off the examples in https://graphql.org/learn/queries/#directives
def test_hero_name_and_include_friends_query(ds): want = """ query Hero($episode: Episode, $withFriends: Boolean!) { hero(episode: $episode) { name friends @include(if: $withFriends) { name } } } """.strip() var = gql.dsl.DSLVariableDefinitions() op = gql.dsl.DSLQuery( ds.Query.hero.args(episode=var.episode).select( ds.Character.name, ds.Character.friends.directives(include={"if": var.withFriends}).select( ds.Character.name, ), ) ) op.variable_definitions = var got = gql.dsl.print_ast(gql.dsl.dsl_gql(Hero=op)) assert got == want
I'm happy to help draft a PR for this if you're open to it. Let me know if you're interested!
Reacted by Hanusz LeszekYes, please, a PR is welcome!
@leszekhanusz, I just opened a PR here: #563
I've been composing queries with gql.dsl and need to use the
@includedirective in a query. Other than #278 I don't see any reference to directives.Are directives supported with
gql.dsland if so what's the syntax?