Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Empty runtime variables with @include directive #50

Copy link
Copy link
Closed
@zcei

Description

@zcei
Issue body actions

Hej folks,

when using the validation rule in combination with a query that provides a variable with a default value, the @include (and potentially also the @skip) directive is causing troubles.

GraphQLError: Argument "if" of required type "Boolean!" was provided the variable "$shouldSkip" which was not provided a runtime value.

I was able to reproduce this with a test case, and I'm wondering what the expected behavior is here.

it('should respect @include(if: false) via default variable value', () => {
  const ast = parse(`
    query Foo ($shouldSkip: Boolean = false) {
      variableScalar(count: 10) @include(if: $shouldSkip)
    }
  `);

  const complexity = getComplexity({
    estimators: [
      simpleEstimator({defaultComplexity: 1})
    ],
    schema,
    query: ast
  });
  expect(complexity).to.equal(0);
});

I see that you're only using graphql-js's getDirectiveValues, which under the hood has a logic that throws the error here.

But to me it sounds like it should first check for the query document default variables.

I feel like we have two options here:

  1. obtain default variables from operation definition here and add these to this.options.variables (or a derivate object of it).
  2. try to convince graphql-js maintainers that there's a flaw in their flow of obtaining runtime values.

As the graphql-js library does not seem to have issues with @include directives, I'm leaning towards (1), wdyt?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.