0.0.1 • Published 4 years ago

@micra/micra-graphql-container v0.0.1

Weekly downloads
31
License
MIT
Repository
-
Last release
4 years ago

About

This is an aggregator of GraphQL schemas and resolvers.

Installation

yarn add @micra/micra-graphql-container

Usage

Micra aims to help you create a modular and type-safe application. To do so, first you need to declare your context and reducers types in a registration file (*.register.d.ts):

// example.d.ts
declare namespace Application {
  interface Context {
    contextVariable: string;
  }

  interface Resolvers {
    Query: {
      hello: import('@micra/micra-graphql-container').Resolver<'world'>;
    };
  }
}

After your types are defined, you can write your resolver that honours the type defined in the registration file:

import { MicraGraphQLContainer } from '@micra/micra-graphql-container';

const graphql = new MicraGraphQLContainer();

graphql.resolver({
  Query: {
    async hello(_parent, _args, context) {
      context.contextVariable // typeof context.contextVariable = string;

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

Resolver type

export type Resolver<
  TResponse = any,
  TSource = undefined,
  TArgs = { [argName: string]: any },
> = (
  source: TSource,
  args: TArgs,
  context: Application.Context,
  info: GraphQLResolveInfo,
) => Promise<TResponse>;

Author