micro-graphql-react
micro-graphql-react copied to clipboard
Directives support
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)
}
}
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?
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.
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.