Skip to content
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

Invalid variable referenced in @include directive #4372

Closed
priti-energysavvy opened this issue Jan 24, 2019 · 2 comments · Fixed by #4373
Closed

Invalid variable referenced in @include directive #4372

priti-energysavvy opened this issue Jan 24, 2019 · 2 comments · Fixed by #4373

Comments

@priti-energysavvy
Copy link

priti-energysavvy commented Jan 24, 2019

I'm duplicating this issue because I've encountered it and it appears the issue was lost and needed to be recreated (ref: https://stackoverflow.com/questions/46004129/invalid-variable-referenced-in-include-directive)
Quoted below vvv

I'll duplicate my issue here hoping that someone may give me a hint to where I'm going wrong.

Here's the schema on GraphCool:

type Reservation implements Node {
  createdAt: DateTime!
    id: ID!@isUnique
  updatedAt: DateTime!
    user: User @relation(name: "UserReservations")
}

type User implements Node {
  createdAt: DateTime!
    id: ID!@isUnique
  updatedAt: DateTime!
    reservations: [Reservation!] !@relation(name: "UserReservations")
}

Here's a fragment in my Angular code:

fragment reservation on Reservation {
  id,
  user @include(
    if :$is_admin) {
    id
  }
}

Here's my GraphQL query:

mutation($id: ID!, $is_admin: Boolean = true) {
  createReservation(userId: $id) {
    ...reservation
  }
}
$ {
  RESERVATION_FRAGMENT.reservation
}

Calling the above mutation using apollo.watchQuery executes successfully on GraphCool, but the client produces the following error:

Error: Invalid variable referenced in @include directive.
at directives.js: 42
at Array.some( < anonymous > )
at Object.shouldInclude(directives.js: 20)
at graphql.js: 27
at Array.forEach( < anonymous > )
at executeSelectionSet(graphql.js: 26)
at graphql.js: 55
at Array.forEach( < anonymous > )
at executeSelectionSet(graphql.js: 26)
at graphql.js: 94
@danilobuerger
Copy link
Contributor

Could you please provide a minimal reproducible sample?

@GreenGremlin
Copy link

I created a currently failing test that reproduces the issue. The issue reproduces when calling graphql-anywhere's filter, propType, 'check', or even graphql with a fragment that uses a variable.

Here's a fairly simple reproducible sample:

import gql from 'graphql-tag';
import propType from 'graphql-anywhere';

const fragment = gql`
  fragment visitor on Visitor {
    pageViews
    user @include(if: $isAuthenticated) {
      username
      name
      email
    }
  }
`;

const propTypes = {
    visitor: propType(fragment),
};

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants