Renaming to nexus

This commit is contained in:
Tim Griesser 2018-12-10 17:37:03 -05:00
parent 2e8af9888a
commit 8031fbae21
51 changed files with 111 additions and 101 deletions

View File

@ -18,18 +18,18 @@ Try it out in the [playground](../playground) to see what we mean!
GraphQL Nexus requires that `graphql` it be installed as a peer dependency. It can be installed with either `npm` or `yarn`.
`yarn add graphql-nexus graphql`
`yarn add nexus graphql`
or
`npm i --save graphql-nexus graphql`
`npm i --save nexus graphql`
## Building a Schema
As documented in the [API reference](../api-reference) GraphQL Nexus provides a consistent, scalable approach to defining GraphQL types in code. Fields are referred to by their GraphQL defined name.
```js
import { objectType, stringArg, fieldArg, makeSchema } from "graphql-nexus";
import { objectType, stringArg, fieldArg, makeSchema } from "nexus";
const Query = objectType("Query", (t) => {
t.field("account", "Account", {

View File

@ -7,11 +7,11 @@ sidebar_label: Library Authors
## Wrapping the API
If you are a library author building tools for GraphQL, we expose the core types
It is recommended that you have `graphql-nexus` specified as a peer dependency rather
It is recommended that you have `nexus` specified as a peer dependency rather
than a direct dependency of your wrapping plugin, so duplicate copies of the library are
not installed.
One example of this pattern is in `@graphql-nexus/contrib` where functions for creating relay-style connections are constructed:
One example of this pattern is in `nexus-contrib` where functions for creating relay-style connections are constructed:
```ts
export const UserConnectionTypes = connectionType("User");
@ -20,7 +20,7 @@ export const UserConnectionTypes = connectionType("User");
Where `connectionType` is really just a wrapper creating two `objectType`:
```ts
import { core } from './graphql-nexus';
import { core } from './nexus';
interface ConnectionConfigFn {
(

View File

@ -15,7 +15,7 @@
"apollo-server": "2.2.0-alpha.2",
"apollo-server-testing": "2.2.0-alpha.2",
"fullstack-tutorial": "apollographql/fullstack-tutorial.git",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2",
"isemail": "^3.2.0",
"sequelize": "^4.41.1",

View File

@ -1,7 +1,7 @@
// @ts-check
import { ApolloServer } from "apollo-server";
import path from "path";
import { makeSchema } from "graphql-nexus";
import { makeSchema } from "nexus";
import isEmail from "isemail";
import * as types from "./schema";
import { Request } from "express";

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
export const Launch = objectType("Launch", (t) => {
t.id("id");

View File

@ -1,4 +1,4 @@
import { objectType, enumType, arg } from "graphql-nexus";
import { objectType, enumType, arg } from "nexus";
export const Mission = objectType("Mission", (t) => {
t.string("name", { nullable: true });

View File

@ -1,4 +1,4 @@
import { objectType, idArg, stringArg } from "graphql-nexus";
import { objectType, idArg, stringArg } from "nexus";
export const Mutation = objectType("Mutation", (t) => {
t.field("bookTrips", "TripUpdateResponse", {

View File

@ -1,5 +1,5 @@
/// <reference path="../fullstackTypes.ts" />
import { objectType, idArg, intArg, stringArg } from "graphql-nexus";
import { objectType, idArg, intArg, stringArg } from "nexus";
import { Utils } from "../typeDefs";
const utils: Utils = require("fullstack-tutorial/final/server/src/utils.js");

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
export const Rocket = objectType("Rocket", (t) => {
t.id("id");

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
export const User = objectType("User", (t) => {
t.id("id");

View File

@ -1796,7 +1796,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
"cssom@>= 0.3.2 < 0.4.0":
version "0.3.4"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.4.tgz#8cd52e8a3acfd68d3aed38ee0a640177d2f9d797"
integrity sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==

View File

@ -6,7 +6,7 @@
"dependencies": {
"apollo-server": "2.2.0-alpha.2",
"githunt-api": "apollographql/GitHunt-API.git",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2"
},
"devDependencies": {

View File

@ -1,7 +1,7 @@
// @ts-check
const { ApolloServer } = require("apollo-server");
const path = require("path");
const { makeSchema } = require("gqliteral");
const { makeSchema } = require("nexus");
const types = require("./schema");
const schema = makeSchema({

View File

@ -6,7 +6,7 @@ const {
intArg,
directiveType,
stringArg,
} = require("gqliteral");
} = require("nexus");
exports.CacheControl = directiveType("cacheControl", (t) => {
t.int("maxAge");
@ -114,7 +114,7 @@ exports.Mutation = objectType("Mutation", (t) => {
/**
* Example of using functions to mixin fields across types
* @type {(t: import('gqliteral').core.ObjectTypeDef) => void}
* @type {(t: import('nexus').core.ObjectTypeDef) => void}
*/
const commonFields = (t) => {
t.int("id", { description: "The SQL ID of this entry" });

View File

@ -6,7 +6,7 @@
},
"dependencies": {
"apollo-server": "^2.2.0",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2",
"ts-node-dev": "^1.0.0-pre.30"
},

View File

@ -4,7 +4,7 @@ import {
enumType,
scalarType,
interfaceType,
} from "graphql-nexus";
} from "nexus";
export const Bar = interfaceType("Bar", (t) => {
t.boolean("ok");

View File

@ -1,5 +1,5 @@
import { ApolloServer } from "apollo-server";
import { makeSchema } from "graphql-nexus";
import { makeSchema } from "nexus";
import path from "path";
import * as types from "./definitions";

View File

@ -1112,7 +1112,7 @@ cross-spawn@^5.0.1:
shebang-command "^1.2.0"
which "^1.2.9"
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
"cssom@>= 0.3.2 < 0.4.0":
version "0.3.4"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.4.tgz#8cd52e8a3acfd68d3aed38ee0a640177d2f9d797"
integrity sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==

View File

@ -6,7 +6,7 @@
},
"dependencies": {
"apollo-server": "^2.2.0",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2",
"ts-node-dev": "^1.0.0-pre.30"
},

View File

@ -1,4 +1,4 @@
import { interfaceType, idArg } from "graphql-nexus";
import { interfaceType, idArg } from "nexus";
import { getFriends } from "../data";
export const Character = interfaceType("Character", (t) => {

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
export const Droid = objectType("Droid", (t) => {
t.description("A mechanical creature in the Star Wars universe.");

View File

@ -1,4 +1,4 @@
import { enumType } from "graphql-nexus";
import { enumType } from "nexus";
/**
* Note: this could also be:

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
export const Human = objectType("Human", (t) => {
t.description("A humanoid creature in the Star Wars universe.");

View File

@ -1,4 +1,4 @@
import { objectType, arg, stringArg } from "graphql-nexus";
import { objectType, arg, stringArg } from "nexus";
import { getHero, getHuman, getDroid } from "../data";
const characterArgs = {

View File

@ -1,6 +1,6 @@
import * as path from "path";
import * as allTypes from "./graphql";
import { makeSchema } from "graphql-nexus";
import { makeSchema } from "nexus";
/**
* Finally, we construct our schema (whose starting query type is the query

View File

@ -1112,7 +1112,7 @@ cross-spawn@^5.0.1:
shebang-command "^1.2.0"
which "^1.2.9"
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
"cssom@>= 0.3.2 < 0.4.0":
version "0.3.4"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.4.tgz#8cd52e8a3acfd68d3aed38ee0a640177d2f9d797"
integrity sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==

View File

@ -7,7 +7,7 @@
"dependencies": {
"apollo-server": "^2.2.5",
"fs-extra": "^7.0.1",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2",
"ts-node-dev": "1.0.0-pre.31",
"typescript": "3.2.0-rc"

View File

@ -1,4 +1,4 @@
import { makeSchema } from "graphql-nexus";
import { makeSchema } from "nexus";
import path from "path";
import * as types from "./types";
import { isObjectType, GraphQLNamedType } from "graphql";

View File

@ -1,4 +1,4 @@
import { objectType, arg } from "graphql-nexus";
import { objectType, arg } from "nexus";
import { nodeType, functionLikeDeclaration, hasTypeParameters } from "./mixins";
import { filteredNodesList } from "./utils";

View File

@ -1,5 +1,5 @@
import ts from "typescript";
import { enumType } from "graphql-nexus";
import { enumType } from "nexus";
import { convertTsEnum } from "./utils";
export const SyntaxKind = enumType("SyntaxKind", convertTsEnum(ts.SyntaxKind));

View File

@ -1,4 +1,4 @@
import { objectType, stringArg } from "graphql-nexus";
import { objectType, stringArg } from "nexus";
import ts from "typescript";
import fs from "fs-extra";

View File

@ -1,4 +1,4 @@
import { interfaceType, arg } from "graphql-nexus";
import { interfaceType, arg } from "nexus";
import { SyntaxKind, JSDoc } from "typescript";
import ts from "typescript";
import { allKnownNodes, syntaxKindFilter } from "./utils";

View File

@ -1,4 +1,4 @@
import { interfaceType, objectType, core } from "graphql-nexus";
import { interfaceType, objectType, core } from "nexus";
import ts from "typescript";
export const JSDoc = objectType("JSDoc", (t) => {

View File

@ -1,4 +1,4 @@
import { core } from "graphql-nexus";
import { core } from "nexus";
import typescript from "typescript";
import { Gen } from "../ts-ast-reader-typegen";

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
import { nodeType } from "./mixins";
export const UNKNOWN_NODE = objectType("UNKNOWN_NODE", (t) => {

View File

@ -1,4 +1,4 @@
import { objectType } from "graphql-nexus";
import { objectType } from "nexus";
import { nodeType } from "./mixins";
export const KeywordTypeNode = objectType("KeywordTypeNode", (t) => {

View File

@ -1,4 +1,4 @@
import { unionType } from "graphql-nexus";
import { unionType } from "nexus";
import ts from "typescript";
export const DeclarationName = unionType("DeclarationName", (t) => {

View File

@ -1,6 +1,6 @@
{
"name": "graphql-nexus",
"version": "0.1.1",
"name": "nexus",
"version": "0.5.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",

View File

@ -2,7 +2,7 @@
import { GraphQLEnumType, GraphQLObjectType } from "graphql";
import { buildTypes, objectType, enumType } from "../";
describe("gqlit", () => {
describe("nexus", () => {
describe("enumType", () => {
const PrimaryColors = enumType<any>("PrimaryColors", (t) => {
t.members(["RED", "YELLOW", "BLUE"]);

View File

@ -102,11 +102,15 @@ export class SchemaBuilder {
constructor(
protected metadata: Metadata,
protected config: Types.Omit<Types.SchemaConfig, "types">
protected config: Types.BuilderConfig
) {
this.nullability = config.nullability || {};
}
getConfig(): Types.BuilderConfig {
return this.config;
}
addType(typeDef: Types.NamedTypeDef | GraphQLNamedType) {
const existingType =
this.finalTypeMap[typeDef.name] || this.pendingTypeMap[typeDef.name];
@ -493,12 +497,12 @@ export class SchemaBuilder {
typeof nullable !== "undefined"
? nullable
: list
? isInput
? nullConfig.inputList
: nullConfig.outputList
: isInput
? nullConfig.input
: nullConfig.output;
? isInput
? nullConfig.inputList
: nullConfig.outputList
: isInput
? nullConfig.input
: nullConfig.output;
if (list) {
const depth = listDepth || 1;
@ -506,8 +510,8 @@ export class SchemaBuilder {
typeof listItemNullable !== "undefined"
? listItemNullable
: isInput
? nullConfig.inputListItem
: nullConfig.outputListItem;
? nullConfig.inputListItem
: nullConfig.outputListItem;
if (Array.isArray(nullableItem) && nullableItem.length !== depth) {
throw new Error(
`Incorrect listItemNullable array length for ${typeConfig.name}${
@ -682,7 +686,7 @@ export function buildTypes<
DirectiveDefs extends Record<string, GraphQLDirective> = any
>(
types: any,
config: Types.Omit<Types.SchemaConfig, "types"> = { outputs: false },
config: Types.BuilderConfig = { outputs: false },
SchemaBuilderClass: typeof SchemaBuilder = SchemaBuilder,
MetadataClass: typeof Metadata = Metadata
): Types.BuildTypes<TypeMapDefs, DirectiveDefs> {
@ -696,6 +700,9 @@ function addTypes(builder: SchemaBuilder, types: any) {
if (!types) {
return;
}
if (typeof types === "function") {
addTypes(builder, types(builder));
}
if (isWrappedTypeDef(types)) {
types = types.type;
}

View File

@ -50,7 +50,7 @@ export class Metadata {
protected typeImports: string[] = [];
protected typegenFile: string = "";
constructor(protected config: Types.Omit<Types.SchemaConfig, "types">) {
constructor(protected config: Types.BuilderConfig) {
if (config.outputs !== false && config.shouldGenerateArtifacts !== false) {
if (config.outputs.typegen) {
this.typegenFile = assertAbsolutePath(

View File

@ -186,10 +186,10 @@ export interface ArgOpts extends FieldOpts {
export interface ArgDefinition
extends Readonly<
ArgOpts & {
type: any;
}
> {} // TODO: Make type safe
ArgOpts & {
type: any;
}
> {} // TODO: Make type safe
export interface DirectiveArgDefinition extends ArgDefinition {
readonly name: string;
@ -263,9 +263,9 @@ export interface InputFieldOpts<GenTypes = any, TypeName = any>
export interface ScalarOpts
extends Pick<
GraphQLScalarTypeConfig<any, any>,
"description" | "serialize" | "parseValue" | "parseLiteral"
> {
GraphQLScalarTypeConfig<any, any>,
"description" | "serialize" | "parseValue" | "parseLiteral"
> {
/**
* Backing type for the scalar
*/
@ -400,13 +400,7 @@ export interface ImportedType {
importPath: string;
}
export interface SchemaConfig extends Nullability {
/**
* All of the GraphQL types. This is an any for simplicity of developer experience,
* if it's an object we get the values, if it's an array we flatten out the
* valid types, ignoring invalid ones.
*/
types: any;
export interface BuilderConfig extends Nullability {
/**
* When the schema starts and `process.env.NODE_ENV !== "production"`,
* artifact files are auto-generated containing the .graphql definitions of
@ -446,6 +440,15 @@ export interface SchemaConfig extends Nullability {
) => TypegenInfo | PromiseLike<TypegenInfo>);
}
export interface SchemaConfig extends BuilderConfig {
/**
* All of the GraphQL types. This is an any for simplicity of developer experience,
* if it's an object we get the values, if it's an array we flatten out the
* valid types, ignoring invalid ones.
*/
types: any;
}
export interface TypegenInfo<GenTypes = any> {
/**
* Headers attached to the generate type output

View File

@ -12,7 +12,7 @@
},
"dependencies": {
"dedent": "^0.7.0",
"graphql-nexus": "0.1.0",
"nexus": "0.5.0",
"graphql": "^14.0.2",
"monaco-editor": "^0.15.5",
"react": "^16.7.0-alpha.2",

View File

@ -3,7 +3,7 @@ import {
interfaceType,
enumType,
makeSchema,
} from "graphql-nexus";
} from "nexus";
const Node = interfaceType("Node", t => {
t.id("id", { description: "ID of the Resource" });

View File

@ -74,10 +74,10 @@ class HomeSplash extends React.Component {
<ProjectTitle />
<PromoSection>
<Button href={pageUrl("blog/2018/11/04/introducing-graphql-nexus")}>
Why GraphQL Nexus?
Why Nexus?
</Button>
<Button href={pageUrl("api-reference", language)}>API Docs</Button>
<Button href="https://github.com/tgriesser/gqliteral/tree/master/examples">
<Button href="https://github.com/tgriesser/nexus/tree/master/examples">
Examples
</Button>
</PromoSection>

View File

@ -21,7 +21,7 @@ import {
idArg,
booleanArg,
core,
} from "graphql-nexus";
} from "nexus";
import { GraphQLSchema, graphql } from "graphql";
import * as monaco from "monaco-editor";
import { useDebounce } from "use-debounce";

View File

@ -19,15 +19,15 @@ const allTypeDefs = [
require("raw-loader!@types/graphql/type/scalars.d.ts"),
require("raw-loader!@types/graphql/type/schema.d.ts"),
require("raw-loader!@types/graphql/type/validate.d.ts"),
require("raw-loader!gqliteral/dist/builder.d.ts"),
require("raw-loader!gqliteral/dist/core.d.ts"),
require("raw-loader!gqliteral/dist/definitions.d.ts"),
require("raw-loader!gqliteral/dist/index.d.ts"),
require("raw-loader!gqliteral/dist/lang.d.ts"),
require("raw-loader!gqliteral/dist/metadata.d.ts"),
require("raw-loader!gqliteral/dist/typegen.d.ts"),
require("raw-loader!gqliteral/dist/types.d.ts"),
require("raw-loader!gqliteral/dist/utils.d.ts"),
require("raw-loader!nexus/dist/builder.d.ts"),
require("raw-loader!nexus/dist/core.d.ts"),
require("raw-loader!nexus/dist/definitions.d.ts"),
require("raw-loader!nexus/dist/index.d.ts"),
require("raw-loader!nexus/dist/lang.d.ts"),
require("raw-loader!nexus/dist/metadata.d.ts"),
require("raw-loader!nexus/dist/typegen.d.ts"),
require("raw-loader!nexus/dist/types.d.ts"),
require("raw-loader!nexus/dist/utils.d.ts"),
];
const files = [
@ -40,15 +40,15 @@ const files = [
"graphql/type/scalars.d.ts",
"graphql/type/schema.d.ts",
"graphql/type/validate.d.ts",
"gqliteral/builder.d.ts",
"gqliteral/core.d.ts",
"gqliteral/definitions.d.ts",
"gqliteral/index.d.ts",
"gqliteral/lang.d.ts",
"gqliteral/metadata.d.ts",
"gqliteral/typegen.d.ts",
"gqliteral/types.d.ts",
"gqliteral/utils.d.ts",
"nexus/builder.d.ts",
"nexus/core.d.ts",
"nexus/definitions.d.ts",
"nexus/index.d.ts",
"nexus/lang.d.ts",
"nexus/metadata.d.ts",
"nexus/typegen.d.ts",
"nexus/types.d.ts",
"nexus/utils.d.ts",
];
files.forEach((file, i) => {

View File

@ -12,7 +12,7 @@ async function linkDir(dir: string, root: string) {
await execAsync("yarn", {
cwd: dir,
});
await execAsync("yarn link graphql-nexus", {
await execAsync("yarn link nexus", {
cwd: dir,
});
await execAsync("rm -rf graphql", {

View File

@ -9,7 +9,7 @@ async function unlinkDir(dir: string) {
await execAsync("rm -rf graphql", {
cwd: path.join(dir, "node_modules"),
});
await execAsync("yarn unlink graphql-nexus", {
await execAsync("yarn unlink nexus", {
cwd: dir,
});
await execAsync("yarn --force", {

View File

@ -14,7 +14,7 @@ const siteConfig = {
tagline:
"Simple, scalable, strongly typed GraphQL schema construction for TypeScript/JavaScript",
// url: "https://tgriesser.com", // Your website URL
baseUrl: "/graphql-nexus/", // Base URL for your project */
baseUrl: "/nexus/", // Base URL for your project */
noIndex: true,
// algolia: {
@ -24,7 +24,7 @@ const siteConfig = {
// }
// Used for publishing and more
projectName: "graphql-nexus",
projectName: "nexus",
organizationName: "tgriesser",
// For no header links in the top nav bar -> headerLinks: [],

View File

@ -1,9 +1,9 @@
// language-ts-graphql-tools
window.addEventListener("load", function() {
var codeToggles = document.getElementsByClassName("code-toggle");
const validLanguages = ["graphql-nexus", "graphqljs", "graphqltools"];
const validLanguages = ["nexus", "graphqljs", "graphqltools"];
const languageLabels = {
graphql-nexus: "GraphQL Nexus",
nexus: "GraphQL Nexus",
graphqljs: "GraphQL JS",
graphqltools: "graphql-tools (Apollo)",
};
@ -11,7 +11,7 @@ window.addEventListener("load", function() {
let preSibling = true;
let currentNode = node;
/**
* @type {Array<{language: 'graphql-nexus' | 'graphqljs' | 'graphqltools', node: Element}>}
* @type {Array<{language: 'nexus' | 'graphqljs' | 'graphqltools', node: Element}>}
*/
const toggleNodes = [];
while (preSibling) {
@ -41,7 +41,7 @@ window.addEventListener("load", function() {
);
break;
}
if (language !== "graphql-nexus") {
if (language !== "nexus") {
currentNode.style.display = "none";
}
const button = document.createElement("button");