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 - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

dist/definitions/queryField.d.ts

6

CHANGELOG.md
# Changelog
### 0.11.0
- Fix allowing nested input types (#68), fixes default type definitions for input fields
- Add `queryField` abstraction to mirror `mutationField`
- Alpha release of `subscriptionField` (working, but undocumented) for GraphQL subscriptions
### 0.10.0

@@ -4,0 +10,0 @@

13

dist/builder.d.ts

@@ -290,4 +290,15 @@ import {

): GraphQLNamedType;
protected getSubscribe(
fieldConfig: NexusOutputFieldDef
):
| GraphQLFieldResolver<
any,
any,
{
[argName: string]: any;
}
>
| undefined;
protected getResolver(
fieldOptions: NexusOutputFieldDef,
fieldConfig: NexusOutputFieldDef,
typeConfig: NexusObjectTypeConfig<any> | NexusInterfaceTypeConfig<any>,

@@ -294,0 +305,0 @@ forInterface?: boolean

21

dist/builder.js

@@ -400,2 +400,3 @@ "use strict";

deprecationReason: fieldConfig.deprecation,
subscribe: forInterface ? undefined : this.getSubscribe(fieldConfig),
};

@@ -560,7 +561,17 @@ };

};
SchemaBuilder.prototype.getResolver = function (fieldOptions, typeConfig, forInterface) {
SchemaBuilder.prototype.getSubscribe = function (fieldConfig) {
var subscribe;
if (fieldConfig.subscribe) {
subscribe = fieldConfig.subscribe;
if (fieldConfig.authorize) {
subscribe = wrapAuthorize(subscribe, fieldConfig.authorize);
}
}
return subscribe;
};
SchemaBuilder.prototype.getResolver = function (fieldConfig, typeConfig, forInterface) {
if (forInterface === void 0) { forInterface = false; }
var resolver;
if (fieldOptions.resolve) {
resolver = fieldOptions.resolve;
if (fieldConfig.resolve) {
resolver = fieldConfig.resolve;
}

@@ -570,4 +581,4 @@ if (!resolver && !forInterface) {

}
if (fieldOptions.authorize) {
resolver = wrapAuthorize(resolver || graphql_1.defaultFieldResolver, fieldOptions.authorize);
if (fieldConfig.authorize && typeConfig.name !== "Subscription") {
resolver = wrapAuthorize(resolver || graphql_1.defaultFieldResolver, fieldConfig.authorize);
}

@@ -574,0 +585,0 @@ return resolver;

@@ -77,1 +77,6 @@ import {

): void;
export interface AsyncIterator<T> {
next(value?: any): Promise<IteratorResult<T>>;
return?(value?: any): Promise<IteratorResult<T>>;
throw?(e?: any): Promise<IteratorResult<T>>;
}

@@ -8,2 +8,3 @@ import {

AuthorizeResolver,
GetGen3,
} from "../typegenTypeHelpers";

@@ -13,6 +14,7 @@ import { NexusArgDef } from "./args";

AllNexusOutputTypeDefs,
NexusInputTypeName,
NexusWrappedType,
AllNexusInputTypeDefs,
} from "./wrapping";
import { BaseScalars } from "./_types";
import { GraphQLFieldResolver } from "graphql";
export interface CommonFieldConfig {

@@ -44,3 +46,3 @@ /**

}
export interface OutputScalarConfig<
export interface CommonOutputFieldConfig<
TypeName extends string,

@@ -54,6 +56,2 @@ FieldName extends string

/**
* Resolve method for the field
*/
resolve?: FieldResolver<TypeName, FieldName>;
/**
* Authorization for an individual field. Returning "true"

@@ -68,2 +66,11 @@ * or "Promise<true>" means the field can be accessed.

}
export interface OutputScalarConfig<
TypeName extends string,
FieldName extends string
> extends CommonOutputFieldConfig<TypeName, FieldName> {
/**
* Resolve method for the field
*/
resolve?: FieldResolver<TypeName, FieldName>;
}
export interface NexusOutputFieldConfig<

@@ -83,2 +90,3 @@ TypeName extends string,

name: string;
subscribe?: GraphQLFieldResolver<any, any>;
};

@@ -179,6 +187,12 @@ /**

}
export interface NexusInputFieldConfig extends ScalarInputFieldConfig<string> {
type: GetGen<"allInputTypes"> | NexusInputTypeName<string>;
export interface NexusInputFieldConfig<
TypeName extends string,
FieldName extends string
> extends ScalarInputFieldConfig<GetGen3<"inputTypes", TypeName, FieldName>> {
type: GetGen<"allInputTypes"> | AllNexusInputTypeDefs<string>;
}
export declare type NexusInputFieldDef = NexusInputFieldConfig & {
export declare type NexusInputFieldDef = NexusInputFieldConfig<
string,
string
> & {
name: string;

@@ -198,6 +212,6 @@ };

id(fieldName: string, opts?: ScalarInputFieldConfig<string>): void;
float(fieldName: string, opts?: ScalarInputFieldConfig<string>): void;
float(fieldName: string, opts?: ScalarInputFieldConfig<number>): void;
field<FieldName extends string>(
fieldName: FieldName,
fieldConfig: NexusInputFieldConfig
fieldConfig: NexusInputFieldConfig<TypeName, FieldName>
): void;

@@ -204,0 +218,0 @@ protected addScalarField(

@@ -62,7 +62,2 @@ "use strict";

exports.mutationType = mutationType;
// export function subscriptionType(
// config: NexusObjectTypeConfig<"Subscription">
// ) {
// return objectType({ ...config, name: "Subscription" });
// }
//# sourceMappingURL=objectType.js.map

@@ -12,11 +12,2 @@ import { GraphQLNamedType } from "graphql";

import { NexusExtendInputTypeDef } from "./extendInputType";
export declare type NexusInputTypeName<T> = T extends NexusInputObjectTypeDef<
infer A
>
? A
: T extends NexusEnumTypeDef<infer B>
? B
: T extends NexusScalarTypeDef<infer C>
? C
: never;
export declare type AllNexusInputTypeDefs<T extends string = string> =

@@ -23,0 +14,0 @@ | NexusInputObjectTypeDef<T>

@@ -179,3 +179,3 @@ "use strict";

imports = [];
Object.keys(importsMap).forEach(function (alias) {
Object.keys(importsMap).sort().forEach(function (alias) {
var _a = importsMap[alias], importPath = _a[0], glob = _a[1];

@@ -182,0 +182,0 @@ imports.push("import " + (glob ? "* as " : "") + alias + " from \"" + importPath + "\"");

@@ -67,3 +67,3 @@ "use strict";

return tslib_1.__awaiter(this, void 0, void 0, function () {
var fs, util, _a, readFile, writeFile, formatTypegen, content, _b, _c, toSave, existing;
var fs, util, _a, readFile, writeFile, mkdir, formatTypegen, content, _b, _c, toSave, existing, dirPath;
return tslib_1.__generator(this, function (_d) {

@@ -80,3 +80,4 @@ switch (_d.label) {

util.promisify(fs.writeFile),
], readFile = _a[0], writeFile = _a[1];
util.promisify(fs.mkdir),
], readFile = _a[0], writeFile = _a[1], mkdir = _a[2];
formatTypegen = null;

@@ -105,6 +106,9 @@ if (typeof this.config.formatTypegen === "function") {

_c = _d.sent(), toSave = _c[0], existing = _c[1];
if (toSave !== existing) {
return [2 /*return*/, writeFile(filePath, toSave)];
}
return [2 /*return*/];
if (!(toSave !== existing)) return [3 /*break*/, 6];
dirPath = path_1.default.dirname(filePath);
return [4 /*yield*/, mkdir(dirPath, { recursive: true })];
case 5:
_d.sent();
return [2 /*return*/, writeFile(filePath, toSave)];
case 6: return [2 /*return*/];
}

@@ -111,0 +115,0 @@ });

{
"name": "nexus",
"version": "0.10.0",
"version": "0.11.0",
"main": "dist",

@@ -5,0 +5,0 @@ "types": "dist",

@@ -16,52 +16,6 @@ <p align="center"><a href="https://nexus.js.org"><img src="https://i.imgur.com/Y5BgDGl.png" width="150" /><a></p>

## Features
- Expressive, declarative API for building schemas
- 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
- Assumes non-null by default, but makes this configurable on per-schema/per-type basis
- Interoperable with vanilla `graphql-js` types, and it's _just_ a [`GraphQLSchema`](https://graphql.org/graphql-js/type/#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
- Lots of good [examples](https://github.com/prisma/nexus/tree/develop/examples) to get you started and thorough [API documentation](https://nexus.js.org/docs/api-core-concepts)
- Full type-safety for free
- Internal structure allows library authors to build more advanced abstractions
- Independent from Prisma, but integrates nicely using the [`nexus-prisma`](https://github.com/prisma/nexus-prisma) plugin
- Allows code re-use by creating higher level "functions" which wrap common fields
## Documentation
You can find the docs for GraphQL Nexus [here](https://nexus.js.org).
## CI
[![CircleCI](https://circleci.com/gh/prisma/nexus.svg?style=svg)](https://circleci.com/gh/prisma/nexus)
## Install
GraphQL Nexus can be installed via the `nexus` package. It also requires `graphql` as a [peer dependency](https://nodejs.org/en/blog/npm/peer-dependencies/):
```
npm install --save nexus graphql
```
or
```
yarn add nexus graphql
```
## Migrate from SDL
If you've been following an [SDL-first](https://www.prisma.io/blog/the-problems-of-schema-first-graphql-development-x1mn4cb0tyl3/) 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**](https://nexus.js.org/converter):
![](https://imgur.com/AbkFWNO.png)
## Examples
All examples of GraphQL Nexus can be found in the [/examples](https://github.com/prisma/nexus/tree/develop/examples) directory.
**"Hello World" GraphQL server with `graphql-yoga`**
<Details>
<Summary>Example: Hello World (with `graphql-yoga`)</Summary>
```ts

@@ -95,110 +49,59 @@ import { queryType, stringArg, makeSchema } from "nexus";

</Details>
All examples of GraphQL Nexus can be found in the [`/examples`](./examples) directory:
<Details>
<Summary>Example: Star Wars</Summary>
- [githunt-api](./examples/githunt-api)
- [ts-ast-reader](./examples/ts-ast-reader)
- [apollo-fullstack](./examples/apollo-fullstack)
- [star-wars](./examples/star-wars)
- [kitchen-sink](./examples/kitchen-sink)
```ts
import { interfaceType, objectType, enumType, arg, stringArg } from "nexus";
If you're interested in examples using the [`nexus-prisma`](https://github.com/prisma/nexus-prisma) plugin, check out the official [`prisma-examples`](https://github.com/prisma/prisma-examples/) repo:
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);
},
});
- [GraphQL blogging app](https://github.com/prisma/prisma-examples/tree/master/typescript/graphql)
- [GraphQL blogging app with authentication & authorization](https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-auth)
- [GraphQL CRUD example](https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-crud)
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",
});
},
});
## Features
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" },
];
- Expressive, declarative API for building schemas
- 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
- Assumes non-null by default, but makes this configurable on per-schema/per-type basis
- Interoperable with vanilla `graphql-js` types, and it's _just_ a [`GraphQLSchema`](https://graphql.org/graphql-js/type/#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
- Lots of good [examples](https://github.com/prisma/nexus/tree/develop/examples) to get you started and thorough [API documentation](https://nexus.js.org/docs/api-core-concepts)
- Full type-safety for free
- Internal structure allows library authors to build more advanced abstractions
- Independent from Prisma, but integrates nicely using the [`nexus-prisma`](https://github.com/prisma/nexus-prisma) plugin
- Allows code re-use by creating higher level "functions" which wrap common fields
export const Episode = enumType({
name: "Episode",
description: "One of the films in the Star Wars Trilogy",
members: OriginalEpisodes,
});
## Documentation
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,
});
},
});
You can find the docs for GraphQL Nexus [here](https://nexus.js.org).
const characterArgs = {
id: stringArg({
required: true,
description: "id of the character",
}),
};
## CI
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.",
}),
};
[![CircleCI](https://circleci.com/gh/prisma/nexus.svg?style=svg)](https://circleci.com/gh/prisma/nexus)
// 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),
});
},
});
## Install
GraphQL Nexus can be installed via the `nexus` package. It also requires `graphql` as a [peer dependency](https://nodejs.org/en/blog/npm/peer-dependencies/):
```
npm install --save nexus graphql
```
</Details>
or
```
yarn add nexus graphql
```
## Migrate from SDL
If you've been following an [SDL-first](https://www.prisma.io/blog/the-problems-of-schema-first-graphql-development-x1mn4cb0tyl3/) 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**](https://nexus.js.org/converter):
![](https://imgur.com/AbkFWNO.png)
---

@@ -205,0 +108,0 @@

@@ -674,5 +674,3 @@ import {

deprecationReason: fieldConfig.deprecation,
// TODO: Need to look into subscription semantics and how
// resolution works for them.
// subscribe: fieldConfig.subscribe,
subscribe: forInterface ? undefined : this.getSubscribe(fieldConfig),
};

@@ -922,4 +920,15 @@ }

protected getSubscribe(fieldConfig: NexusOutputFieldDef) {
let subscribe: undefined | GraphQLFieldResolver<any, any>;
if (fieldConfig.subscribe) {
subscribe = fieldConfig.subscribe;
if (fieldConfig.authorize) {
subscribe = wrapAuthorize(subscribe, fieldConfig.authorize);
}
}
return subscribe;
}
protected getResolver(
fieldOptions: NexusOutputFieldDef,
fieldConfig: NexusOutputFieldDef,
typeConfig: NexusObjectTypeConfig<any> | NexusInterfaceTypeConfig<any>,

@@ -929,4 +938,4 @@ forInterface: boolean = false

let resolver: undefined | GraphQLFieldResolver<any, any>;
if (fieldOptions.resolve) {
resolver = fieldOptions.resolve;
if (fieldConfig.resolve) {
resolver = fieldConfig.resolve;
}

@@ -936,6 +945,6 @@ if (!resolver && !forInterface) {

}
if (fieldOptions.authorize) {
if (fieldConfig.authorize && typeConfig.name !== "Subscription") {
resolver = wrapAuthorize(
resolver || defaultFieldResolver,
fieldOptions.authorize
fieldConfig.authorize
);

@@ -942,0 +951,0 @@ }

@@ -82,1 +82,7 @@ import {

}
export interface AsyncIterator<T> {
next(value?: any): Promise<IteratorResult<T>>;
return?(value?: any): Promise<IteratorResult<T>>;
throw?(e?: any): Promise<IteratorResult<T>>;
}

@@ -8,2 +8,3 @@ import {

AuthorizeResolver,
GetGen3,
} from "../typegenTypeHelpers";

@@ -13,6 +14,7 @@ import { NexusArgDef } from "./args";

AllNexusOutputTypeDefs,
NexusInputTypeName,
NexusWrappedType,
AllNexusInputTypeDefs,
} from "./wrapping";
import { BaseScalars } from "./_types";
import { GraphQLFieldResolver } from "graphql";

@@ -46,3 +48,3 @@ export interface CommonFieldConfig {

export interface OutputScalarConfig<
export interface CommonOutputFieldConfig<
TypeName extends string,

@@ -56,6 +58,2 @@ FieldName extends string

/**
* Resolve method for the field
*/
resolve?: FieldResolver<TypeName, FieldName>;
/**
* Authorization for an individual field. Returning "true"

@@ -71,2 +69,12 @@ * or "Promise<true>" means the field can be accessed.

export interface OutputScalarConfig<
TypeName extends string,
FieldName extends string
> extends CommonOutputFieldConfig<TypeName, FieldName> {
/**
* Resolve method for the field
*/
resolve?: FieldResolver<TypeName, FieldName>;
}
export interface NexusOutputFieldConfig<

@@ -84,2 +92,3 @@ TypeName extends string,

name: string;
subscribe?: GraphQLFieldResolver<any, any>;
};

@@ -248,7 +257,10 @@

export interface NexusInputFieldConfig extends ScalarInputFieldConfig<string> {
type: GetGen<"allInputTypes"> | NexusInputTypeName<string>;
export interface NexusInputFieldConfig<
TypeName extends string,
FieldName extends string
> extends ScalarInputFieldConfig<GetGen3<"inputTypes", TypeName, FieldName>> {
type: GetGen<"allInputTypes"> | AllNexusInputTypeDefs<string>;
}
export type NexusInputFieldDef = NexusInputFieldConfig & {
export type NexusInputFieldDef = NexusInputFieldConfig<string, string> & {
name: string;

@@ -295,3 +307,3 @@ };

float(fieldName: string, opts?: ScalarInputFieldConfig<string>) {
float(fieldName: string, opts?: ScalarInputFieldConfig<number>) {
this.addScalarField(fieldName, "Float", opts);

@@ -302,3 +314,3 @@ }

fieldName: FieldName,
fieldConfig: NexusInputFieldConfig
fieldConfig: NexusInputFieldConfig<TypeName, FieldName>
) {

@@ -305,0 +317,0 @@ this.typeBuilder.addField(

@@ -116,7 +116,1 @@ import {

}
// export function subscriptionType(
// config: NexusObjectTypeConfig<"Subscription">
// ) {
// return objectType({ ...config, name: "Subscription" });
// }

@@ -13,10 +13,2 @@ import { GraphQLNamedType } from "graphql";

export type NexusInputTypeName<T> = T extends NexusInputObjectTypeDef<infer A>
? A
: T extends NexusEnumTypeDef<infer B>
? B
: T extends NexusScalarTypeDef<infer C>
? C
: never;
export type AllNexusInputTypeDefs<T extends string = string> =

@@ -23,0 +15,0 @@ | NexusInputObjectTypeDef<T>

@@ -322,3 +322,3 @@ import {

Object.keys(importsMap).forEach((alias) => {
Object.keys(importsMap).sort().forEach((alias) => {
const [importPath, glob] = importsMap[alias];

@@ -325,0 +325,0 @@ imports.push(

@@ -72,5 +72,6 @@ import { GraphQLSchema, lexicographicSortSchema, printSchema } from "graphql";

const util = require("util") as typeof import("util");
const [readFile, writeFile] = [
const [readFile, writeFile, mkdir] = [
util.promisify(fs.readFile),
util.promisify(fs.writeFile),
util.promisify(fs.mkdir),
];

@@ -92,2 +93,4 @@ let formatTypegen: TypegenFormatFn | null = null;

if (toSave !== existing) {
const dirPath = path.dirname(filePath)
await mkdir(dirPath, { recursive: true })
return writeFile(filePath, toSave);

@@ -94,0 +97,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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