stackshareio/graphql-cache

[FEAT] Cache introspection queries

alecgorge opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
This project looks almost perfect for addressing some hotspots in our code!

Describe the solution you'd like
I would like to be able to apply caching to the introspection fields/queries. Introspection queries are currently the heaviest GraphQL query we face because we have a very large schema—but our schema doesn't change while the server is running. I plan on using a cache key of the build number + schema name in production.

It isn't clear to me how to attach caching to these automatically provided fields.

Additional context
We are open to other solutions besides caching at the field level but aren't keen on directly matching against the query because when we open up our GraphQL API to more 3rd parties we can't ensure they always introspect in the same way.

query IntrospectionQuery {
  __schema {
    queryType {
      name
    }
    mutationType {
      name
    }
    subscriptionType {
      name
    }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
      }
    }
  }
}

fragment FullType on __Type {
  kind
  name
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}

fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}

@alecgorge I'm sorry it has taken so long to respond to this issue. I no longer work at Stackshare and don't have write access to the repo anymore.

That's an interesting use case that I haven't seen before (caching introspection queries). I'm not entirely sure whether graphql-cache is the write tool for this issue or not. We make a lot of assumptions about what it is that we're caching. I'll do some investigation and see if I can come up with a way to accomplish this in a stable way.