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

Directives support #78

Open
Kostanos opened this issue Jul 22, 2022 · 3 comments
Open

Directives support #78

Kostanos opened this issue Jul 22, 2022 · 3 comments

Comments

@Kostanos
Copy link

Hey, do you have support for directives? I didn't find it in the code yet.

ex: https://www.apollographql.com/docs/apollo-server/schema/directives/

It may make the library bigger, but maybe make it as optional plugin? so, if someone need it, just add it to the project.

In particular I use a lot something like this:

query Products($includeData: Boolean, $id: UUID!) {
  products(id: $id) {
    id
    name
    data @include(if: $includeData)
  }
}
@arackaf
Copy link
Owner

arackaf commented Jul 22, 2022

Can you help me understand what this project would need to do? Aren't directives something that's in the graphql endpoint?

Can this graphql client not already send queries and mutations to an endpoint that has directives, and if not, what would need to be added to make it so?

@Kostanos
Copy link
Author

Some of them are client side some are server side.
I believe those are client side. Basically, the example above says, request the data field from the server only if includeData is true. This is very useful when you have several places which uses the same query but with different set of fields. You can use Fragments with it also, but @include, @skip directives gives you more flexibility yet...

Another example of directive use apart of one that you can find in the link that I shared is this one:

query Products(...) @api(name: "main") {...}
query Products(...) @api(name: "external") {...}

So, you can define the API at level of the query, without needing to use different client in the code..

You can find more info in internet regarding. They are very powerful part of GraphQL.

@arackaf
Copy link
Owner

arackaf commented Jul 22, 2022

Ohhhh - yeah no I don't think this would work in this project. I'm pretty sure you'd have to parse the query into an ast, and I'm not including any of those libraries here (it would explode the bundle size, and really runs contrary to my goals here).

Or if I'm wrong and you could do it without shipping that stuff, then speak up. Or if you think you could PR it in a way that it was optionally included only if needed, I'd be open to that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants