import { buildSchema } from 'graphql' ; import { makeExecutableSchema , IExecutableSchemaDefinition , } from '@graphql-tools/schema' ; import { addMocksToSchema } from '@graphql-tools/mock' ; export function augmentTypeDefsWithCacheControlSupport ( typeDefs ) { return ( `
  enum CacheControlScope {
    PUBLIC
    PRIVATE
  }

  directive @cacheControl(
    maxAge: Int
    scope: CacheControlScope
    inheritMaxAge: Boolean
  ) on FIELD_DEFINITION | OBJECT | INTERFACE | UNION
` + typeDefs ) ; } export function buildSchemaWithCacheControlSupport ( source ) { return buildSchema ( augmentTypeDefsWithCacheControlSupport ( source ) ) ; } export function makeExecutableSchemaWithCacheControlSupport ( options ) { return addMocksToSchema ( { schema : makeExecutableSchema ( { ... options , typeDefs : augmentTypeDefsWithCacheControlSupport ( options . typeDefs ) , } ) , preserveResolvers : true , } ) ; }