Skip to content

Use of @skip and @ignore directives with gql.dsl #479

Description

@david-waterworth

I've been composing queries with gql.dsl and need to use the @include directive in a query. Other than #278 I don't see any reference to directives.

Are directives supported with gql.dsl and if so what's the syntax?

Activity

  1. leszekhanusz commented on May 17, 2024

    @leszekhanusz
    Collaborator

    Directives are not currently supported with the dsl module.

  2. kasbaker commented on Aug 22, 2025

    @kasbaker
    Contributor

    @leszekhanusz, I was looking at the graphql-core library 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 @defer and @stream are 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 of graphql-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!

  3. leszekhanusz commented on Aug 22, 2025

    @leszekhanusz
    Collaborator

    Yes, please, a PR is welcome!

  4. kasbaker commented on Aug 27, 2025

    @kasbaker
    Contributor

    @leszekhanusz, I just opened a PR here: #563

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions