Skip to content

Thinkmill/graphql-ts

Repository files navigation

@graphql-ts/schema

@graphql-ts/schema is a thin wrapper around GraphQL.js providing type-safety for constructing GraphQL Schemas while avoiding type-generation, declaration merging and decorators.

import { g } from "@graphql-ts/schema";
import { GraphQLSchema, graphql } from "graphql";

const Query = g.object()({
  name: "Query",
  fields: {
    hello: g.field({
      type: g.String,
      resolve() {
        return "Hello!";
      },
    }),
  },
});

const schema = new GraphQLSchema({
  query: Query.graphQLType,
});

graphql({
  source: `
    query {
      hello
    }
  `,
  schema,
}).then((result) => {
  console.log(result);
});