Go to file
Leonardo Dino 5b900b156a
fix(connectionPlugin): allow first and last to be zero (#436)
Co-authored-by: Jason Kuhrt <jason.kuhrt@dialogue.co>
2020-07-01 14:49:09 -04:00
.github tests: add windows to os matrix (#405) 2020-06-10 10:02:04 -04:00
.vscode fix: use ts declaration source maps for better ide dx (#199) 2019-08-21 22:14:20 -04:00
docs chore(website): fix links (#433) 2020-05-05 16:07:55 +02:00
examples chore(docs): Update repo name in examples readme (#443) 2020-06-03 16:28:49 -04:00
src fix(connectionPlugin): allow first and last to be zero (#436) 2020-07-01 14:49:09 -04:00
tests fix(connectionPlugin): allow first and last to be zero (#436) 2020-07-01 14:49:09 -04:00
website chore: post-release update examples 2020-06-03 16:11:26 -04:00
.gitignore feat: publish esm builds (#438) 2020-05-12 13:58:58 -04:00
.prettierrc WIP 2018-11-05 19:55:28 -05:00
CHANGELOG.md chore: update changelog 2020-03-30 16:39:33 -04:00
CONTRIBUTING.md Renaming 2018-11-03 23:44:05 -04:00
LICENSE.md Update documentation & site 2019-02-05 02:33:57 -05:00
README.md chore(docs): fix typo on readme file (#420) 2020-04-29 21:37:29 -04:00
codecov.yml feat(epic): 0.12.0 Plugin System and Internal Refactor (#242) 2019-11-07 16:39:33 -05:00
jest.config.js feat(epic): 0.12.0 Plugin System and Internal Refactor (#242) 2019-11-07 16:39:33 -05:00
package.json tests: add windows to os matrix (#405) 2020-06-10 10:02:04 -04:00
renovate.json chore: Disable Renovate (#430) 2020-04-29 23:11:42 -04:00
tsconfig.cjs.json feat: publish esm builds (#438) 2020-05-12 13:58:58 -04:00
tsconfig.esm.json feat: publish esm builds (#438) 2020-05-12 13:58:58 -04:00
tsconfig.json feat: publish esm builds (#438) 2020-05-12 13:58:58 -04:00
tslint.json docs(example): show nexus + zeit + typescript (#274) 2019-10-18 13:51:39 +02:00
yarn.lock tests: add windows to os matrix (#405) 2020-06-10 10:02:04 -04:00

README.md

Nexus Schema

trunk npm version

Declarative, code-first and strongly typed GraphQL schema construction for TypeScript & JavaScript.

This is a component of the Nexus Framework but can be used as well standalone.

Installation

npm install @nexus/schema graphql

Note you must also add graphql. Nexus Schema pins to it as a peer dependency.

Features

  • Expressive, declarative API for building schemas
  • Full type-safety for free
  • Powerful plugin system
  • No need to re-declare interface fields per-object
  • Optionally possible to reference types by name (with autocomplete)
    Rather than needing to import every single piece of the schema
  • Interoperable with vanilla graphql-js types, and it's just a GraphQLSchema
    So it fits in just fine with existing community solutions of apollo-server, graphql-middleware, etc.
  • Inline function resolvers
    For when you need to do simple field aliasing
  • Auto-generated graphql SDL schema
    Great for when seeing how any code changes affected the schema
  • DRY-up schema design
    Create higher level "functions" which wrap common fields

Example

import { queryType, stringArg, makeSchema } from "@nexus/schema";
import { GraphQLServer } from "graphql-yoga";

const Query = queryType({
  definition(t) {
    t.string("hello", {
      args: { name: stringArg({ nullable: true }) },
      resolve: (parent, { name }) => `Hello ${name || "World"}!`,
    });
  },
});

const schema = makeSchema({
  types: [Query],
  outputs: {
    schema: __dirname + "/generated/schema.graphql",
    typegen: __dirname + "/generated/typings.ts",
  },
});

const server = new GraphQLServer({
  schema,
});

server.start(() => `Server is running on http://localhost:4000`);

More examples can be found in the /examples directory:

Documentation

You can find the docs for Nexus Schema here.

Migrate from SDL

If you've been following an SDL-first approach to build your GraphQL server and want to see what your code looks like when written with GraphQL Nexus, you can use the SDL converter.