-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support the @include and @skip directives #245
Comments
@vladar Thanks for filing an issue - Relay doesn't support arbitrary directives (it uses the |
Thanks for clarifications. But |
@vladar touche. yes, we should support these. I'll update the title of this issue to reflect this. |
Is it necessary for Relay to be cutting out the directives? Presumably if they were left intact it would be possible to support arbitrary ones as well. |
@AndrewIngram, that's a good point. I think the reason we've defaulted to a conservative policy here so far is that directives can drastically alter the semantics of a query, and Relay very much wants to be able to both statically analyze component queries and dynamically construct new ones at runtime (for example, to compute minimal diff queries in order to request only data that is not already present in the store). In addition to that, directives as they exist in open source GraphQL are a relatively new addition to the language, so support for them is still pretty recent and basic. But yes, we should not only handle directives in the spec, but also consider what the implications of "passing through" any other directives that we don't explicitly support might be. |
Incidentally, this is the use case I'm trying to support:
At the moment, I'm handing this by making the users connection return a promise with an empty array if there's no query. But ideally we wouldn't even be hitting that part of the graph at all |
+1 |
This is fixed in master and will be available in the next release :-) |
Did this make it into the latest release? I'm currently using |
Any word on this? @josephsavona doesn't seem to be working for me either. |
@josephsavona I can confirm it: the |
From what I saw the babel plugin just returned an error for the fragment, which was then called. |
@aweary can you provide the fragment itself and the error message & stack (if present)? |
Here's what I am seeing: this is the fragment: initialVariables: {
projectId: null,
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
${SelectProject.getFragment('viewer')}
node(id: $projectId) @include(if: $projectId) {
${ProjectDetails.getFragment('project')}
}
}
`,
}, The query that's being sent includes the |
@guigrpa I see what's happening - this is not about directives. Relay requires that the As for why it isn't working now, GraphQL is rejecting the query since |
@josephsavona I should note that the error I was getting was due to using the If I use it on each field it seems to be working just fine 👍 |
Thanks everyone for confirming that directives themselves are working as-expected. I'll leave this issue closed. @guigrpa - please feel free to ask follow-up questions about the |
I tried to add directives to my GraphQL query in Container, like:
But they were cut out by Relay. Am I missing something?
The text was updated successfully, but these errors were encountered: