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

info.cacheControl is undefined in custom queries #4429

Open
SeanDoyleGit opened this issue Nov 30, 2020 · 1 comment
Open

info.cacheControl is undefined in custom queries #4429

SeanDoyleGit opened this issue Nov 30, 2020 · 1 comment
Assignees

Comments

@SeanDoyleGit
Copy link
Contributor

SeanDoyleGit commented Nov 30, 2020

Bug report

info.cacheControl is undefined in custom queries that are called from keystone.executeGraphQL

Describe the bug

Custom queries called from keystone.executeGraphQL will have info.cacheControl be undefined. info.cacheControl needs to be defined in all custom queries so the correct cache headers are applied.

For example if a query has a cache scope of PUBLIC and calls another query with a scope of PRIVATE this bug will prevent the PRIVATE scope from being applied and result in the caching of sensitive user information.

To Reproduce

Implement the following changes to the blog example in the keystone repo.

run yarn add apollo-server-express and add const { gql } = require('apollo-server-express'); to the index.js file in the blog example project.

Then add these two custom queries to the schema by adding the following code to the index.js file in the blog example project.

keystone.extendGraphQLSchema({
  queries: [
    {
      schema: 'getHello: String',
      resolver: async (obj, args, auth, info) => {
        info.cacheControl.setCacheHint({ maxAge: 60, scope: 'PUBLIC' });

        const context = keystone.createContext({ skipAccessControl: true });

        const query = gql`
          {
            getWorld
          }
        `;

        const { data, errors } = await keystone.executeGraphQL({ context, query });

        console.log(data, errors);

        return 'hello ' + data.getWorld;
      },
    },
    {
      schema: 'getWorld: String',
      resolver: async (obj, args, auth, info) => {
        info.cacheControl.setCacheHint({ maxAge: 1, scope: 'PRIVATE' });

        return 'world';
      },
    },
  ],
});

Run the blog example project and open the graphql playground http://localhost:3000/admin/graphiql

run the following query in the playground

{
  getHello
  getWorld
}

Expected result:

{
  "data": {
    "getHello": "hello world",
    "getWorld": "world"
  }
}

Actual result:

{
  "data": {
    "getHello": "hello null",
    "getWorld": "world"
  }
}

The getWorld query when run on its own returns the "world" string, however when it is called using keystone.executeGraphQL in the getHello query, the getWorld query returns null and throws the following error,
TypeError: Cannot read property 'setCacheHint' of undefined

This is due to info.cacheControl being undefined when a query is called from keystone.executeGraphQL

@stale
Copy link

stale bot commented Apr 18, 2021

It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :)

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

4 participants