@micra/micra-graphql-container
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@micra/micra-graphql-container

version issues prs


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

Readme

Keywords

none

Package Sidebar

Install

npm i @micra/micra-graphql-container

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

9.11 kB

Total Files

11

Last publish

Collaborators

  • olavo.a.santos