apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Allow SchemaLink.Options.schema as async function

Open RishikeshDarandale opened this issue 5 years ago • 0 comments

Allow SchemaLink.Options.schema as async function

I am using type-graphql with apollo server and for SSR apollo client I want to use it SchemaLink. type-graphql gives a async method to create the schema as below:

const schema = await buildSchema({
  resolvers: [FirstResolver, SecondResolver],
});

If schema can alternatively provide a way to accept the async function which returns the graphql schema, then schemalink can be created as below:

const graphqlClient = new ApolloClient({
  ssrMode: true,
  cache: new InMemoryCache(),
  link: new SchemaLink({ schema: async () =>  { return await buildSchema({
  resolvers: [FirstResolver, SecondResolver],
})}})
});

So, can we allow it as below?

export namespace SchemaLink {
  export type ResolverContext = Record<string, any>;
  export type SchemaFunction = ( ) => GraphQLSchema | PromiseLike<GraphQLSchema>;
  export type ResolverContextFunction = (
    operation: Operation,
  ) => ResolverContext | PromiseLike<ResolverContext>;

  export interface Options {
    /**
     * The schema to generate responses from.
     */
    schema: GraphQLSchema | SchemaFunction;

    /**
     * The root value to use when generating responses.
     */
    rootValue?: any;

    /**
     * A context to provide to resolvers declared within the schema.
     */
    context?: ResolverContext | ResolverContextFunction;
  }
}

RishikeshDarandale avatar Sep 25 '20 07:09 RishikeshDarandale