Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nexus

Package Overview
Dependencies
Maintainers
3
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexus

Scalable, strongly typed GraphQL schema development

  • 0.9.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
99K
increased by2.95%
Maintainers
3
Weekly downloads
 
Created
Source

GraphQL Nexus

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

Note: This library is independent of the Prisma database client. For the prisma-plugin, visit https://github.com/prisma/nexus-prisma

Read the Documentation

Check out the Examples

yarn add nexus // or npm install nexus

Example Star Wars Schema:

import { interfaceType, objectType, enumType, arg, stringArg } from "nexus";

export const Character = interfaceType({
  name: "Character",
  definition: (t) => {
    t.string("id", { description: "The id of the character" });
    t.string("name", { description: "The name of the character" });
    t.list.field("friends", {
      type: Character,
      description:
        "The friends of the character, or an empty list if they have none.",
      resolve: (character) => getFriends(character),
    });
    t.list.field("appearsIn", {
      type: "Episode",
      description: "Which movies they appear in.",
      resolve: (o) => o.appears_in,
      args: {
        id: idArg({ required: true }),
      },
    });
    t.resolveType((character) => character.type);
  },
});

export const Droid = objectType({
  name: "Droid",
  description: "A mechanical creature in the Star Wars universe.",
  definition(t) {
    t.implements(Character);
    t.string("primaryFunction", {
      description: "The primary function of the droid.",
      resolve: (o) => o.primary_function || "N/A",
    });
  },
});

const OriginalEpisodes = [
  { name: "NEWHOPE", value: 4, description: "Released in 1977." },
  { name: "EMPIRE", value: 5, description: "Released in 1980." },
  { name: "JEDI", value: 6, description: "Released in 1983" },
];

export const Episode = enumType({
  name: "Episode",
  description: "One of the films in the Star Wars Trilogy",
  members: OriginalEpisodes,
});

export const Human = objectType({
  name: "Human",
  description: "A humanoid creature in the Star Wars universe.",
  definition(t) {
    t.implements(Character);
    t.string("homePlanet", {
      nullable: true,
      description: "The home planet of the human, or null if unknown.",
      resolve: (o) => o.home_planet || null,
    });
  },
});

const characterArgs = {
  id: stringArg({
    required: true,
    description: "id of the character",
  }),
};

const heroArgs = {
  episode: arg({
    type: "Episode",
    description:
      "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.",
  }),
};

// or queryType({...
export const Query = objectType({
  name: "Query",
  definition(t) {
    t.field("hero", {
      type: Character,
      args: heroArgs,
      resolve: (_, { episode }) => getHero(episode),
    });
    t.field("human", {
      type: Human,
      args: characterArgs,
      resolve: (_, { id }) => getHuman(id),
    });
    t.field("droid", {
      type: Droid,
      args: characterArgs,
      resolve: (_, { id }) => getDroid(id),
    });
  },
});

License (MIT)

(c) 2018-2019 Tim Griesser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 05 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc