Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Allow specifying cacheControl attributes on Types and Fields #1032

Closed
1 task
kbrandwijk opened this issue Oct 25, 2017 · 6 comments
Closed
1 task

Allow specifying cacheControl attributes on Types and Fields #1032

kbrandwijk opened this issue Oct 25, 2017 · 6 comments

Comments

@kbrandwijk
Copy link
Contributor

kbrandwijk commented Oct 25, 2017

What feature are you missing?
I am trying to configure caching on my Apollo API Gateway. For this, I need to add @cacheControl directives to my Types and fields. When I try to do that, the server doesn't throw any error, but the directives are silently removed. Unfortunately, mergeSchemas does not allow redefining fields, so it would be helpful if I could add them on the Graphcool side.

Also, the top-level queries that are generated are not accessible from the schema. It would be nice to be able to define cacheControl attributes for the generated query fields as well somehow.

Apollo Cache Control is an open standard, that will not only be implemented by Apollo Server, but also Sangria, etc. (according to their docs), so this is not a 'vendor-specific' thing.

How could this feature look like in detail? Tradeoffs?

  • Do not remove additional directives.
  • Proposal for generated query fields is to take the cacheControl attribute off the Type, so if I define:
type Post @model @cacheControl(maxAge: 30) {
 ...
}

Then the generated queries would also get that setting:

type Query {
   allPosts(...) @cacheControl(maxAge: 30)
   Post (...) @cacheControl(maxAge: 30)
}

Depends on:

@kbrandwijk kbrandwijk changed the title Allow other directives on Types Allow other directives on Types and Fields Oct 25, 2017
@kbrandwijk kbrandwijk changed the title Allow other directives on Types and Fields Allow specifying cacheControl attributes on Types and Fields Oct 25, 2017
@marktani
Copy link
Contributor

Can you provide links to more resources about @cacheControl? :)

@kbrandwijk
Copy link
Contributor Author

I have a working example here: https://github.com/kbrandwijk/graphcool-gateway-apollo-engine-demo#caching-example. The reason behind this issue is that adding directives to an existing field in a Gateway is difficult (see: ardatan/graphql-tools#451).
This is not necessarily just about cacheControl, but potentially about any directive not recognized by Graphcool, but useful 'downstream', like the new stream directive, or any other for that matter.

@lastmjs
Copy link

lastmjs commented Mar 7, 2018

This may be the wrong place, but has this been addressed? I could really use custom directives defined in my datamodel.graphl, but Prisma removes them when generating prisma.graphl. I would like to define custom directives and be able to provide their implementation, and I am also running into the limitations of mergeSchemas

@marktani
Copy link
Contributor

marktani commented Mar 8, 2018

Since this discussion ended ~half a year ago, a lot has changed in the GraphQL ecosystem.
You should be able to define directives in your application schema, and also define their logic there.

Feel free to revisit this discussion in a new issue if you feel that this approach could be extended 🙂

@kbrandwijk
Copy link
Contributor Author

@marktani I think it would be very helpful if directives would be 'preserved' across Prisma. When importing Prisma types into your schema, it's still hard to add directives to them.

@marktani
Copy link
Contributor

marktani commented Mar 8, 2018

Yup, let's continue the discussion here: #1228 🙂

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

No branches or pull requests

4 participants