Skip to content

Commit

Permalink
Merge branch 'main' into tgriesser/feat/sdl-directives
Browse files Browse the repository at this point in the history
* main: (33 commits)
  fix: incorrect logic in backward pagination (#1084)
  fix: update snapshots for change in #1083
  chore: change facebook.github.io to relay.dev links (#1083)
  feat: allow specifying custom directives in makeSchema (#1065)
  Update comment for `shouldGenerateArtifacts` (#1057)
  feat: Run both formatTypegen and prettier formatter if given (#1042)
  feat: allow specifying custom directives in makeSchema (#1064)
  feat: Use ReadonlyArray in typings (#1041)
  chore: use dripip reusable workflow
  docs: Update npm badge
  v1.3.0
  chore: add test confirming v16 schema compat (#1054)
  chore: update github workflows (#1053)
  feat: add GraphQL 16 support (#977)
  chore(docs): fix typos (#1005)
  chore(docs): fix typo 06-chapter-5-persisting-data-via-prisma.mdx (#1007)
  chore(docs): fix typo 04-why-nexus.mdx (#1008)
  chore(docs): fix typo 030-neuxs-framework-prisma-users.mdx (#1016)
  chore(docs): fix typo 05-chapter-4-testing-your-api.mdx (#1023)
  chore(docs): fix typo in 07-chapter-6-testing-with-prisma.mdx (#1024)
  ...
  • Loading branch information
tgriesser committed May 15, 2022
2 parents 54fa7a3 + 123dc61 commit c85898e
Show file tree
Hide file tree
Showing 124 changed files with 6,266 additions and 3,681 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ on:
- pull_request

jobs:
graphql-14:
graphql-15:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- name: Install Dependencies
run: yarn --frozen-lockfile || yarn --frozen-lockfile
- name: Check Formatting
run: yarn format:ci
- name: Install GraphQL@14.x
run: yarn add graphql@^14.5.8
run: yarn --frozen-lockfile && yarn format:ci
- name: Install GraphQL@15.x
run: yarn add graphql@^15
- name: Test
run: yarn -s test:ci --testPathIgnorePatterns v15
run: yarn -s test:ci

test:
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -58,7 +56,7 @@ jobs:
# rm examples/star-wars/star-wars-schema.graphql
# node examples/star-wars/dist/schema.js
# git diff --exit-code
node-version: [12.x]
node-version: [14.x]
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
35 changes: 12 additions & 23 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ on:
branches: [main]

jobs:
graphql-14:
graphql-15:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x
- name: Install Dependencies
run: yarn --frozen-lockfile || yarn --frozen-lockfile
- name: Install GraphQL@14.x
run: yarn add graphql@^14.5.8
run: yarn --frozen-lockfile && yarn format:ci
- name: Install GraphQL@15.x
run: yarn add graphql@^15
- name: Test
run: yarn -s test:ci --testPathIgnorePatterns v15
run: yarn -s test:ci

test:
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x]
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
# rm examples/star-wars/star-wars-schema.graphql
# node examples/star-wars/dist/schema.js
# git diff --exit-code
node-version: [12.x]
node-version: [14.x]
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -80,18 +80,7 @@ jobs:

release-canary:
needs: [test, test-examples]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
- name: Install Dependencies
run: yarn --frozen-lockfile || yarn --frozen-lockfile
- name: Release Canary
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
yarn -s dripip preview --json > result.json
jq '.' < result.json
uses: prisma-labs/dripip/.github/workflows/release.yml@master
secrets:
npmToken: ${{secrets.NPM_TOKEN}}
githubToken: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nexus

[![trunk](https://github.com/graphql-nexus/nexus/workflows/trunk/badge.svg)](https://github.com/graphql-nexus/nexus/actions/workflows/trunk.yml)
[![npm version](https://badge.fury.io/js/%40nexus%2Fschema.svg)](https://badge.fury.io/js/%40nexus%2Fschema)
[![npm version](https://badge.fury.io/js/nexus.svg)](https://badge.fury.io/js/nexus)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Start by creating your project directory, initializing your `package.json`, and
```bash-symbol copy
mkdir nexus-tutorial && cd nexus-tutorial
npm init -y
npm add nexus graphql apollo-server
npm install nexus graphql apollo-server
```

> Note: `nexus` works with any GraphQL compliant server. We'll use `apollo-server` in this tutorial, but you're free to use whichever fits your use-case best.
We'll also need `typescript` and `ts-node-dev` as dev dependencies. `ts-node-dev` will enable you to transpile your TS files on the fly and restart your API on changes.

```bash-symbol copy
npm add --save-dev typescript ts-node-dev
npm install --save-dev typescript ts-node-dev
```

To properly get full advantage of TypeScript, we'll need a `tsconfig.json` file. Create one at the root of your project and copy paste the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ During this tutorial, you'll use the [Jest testing framework](https://jestjs.io/
First, install `jest` and accompanying tools.

```bash-symbol copy
npm add --save-dev jest @types/jest ts-jest graphql-request get-port
npm install --save-dev jest @types/jest ts-jest graphql-request get-port@5.1.1
```

Then, configure jest and npm scripts in your `package.json`
Expand Down Expand Up @@ -88,7 +88,7 @@ mkdir tests && touch tests/Post.test.ts

To ease testing, we'll create a small utility that we'll call `createTestContext`, which is designed for running integration tests.

When run, it will boot your app in the same process as the test suite and expose an interface for your tests to interact with it. Jest runs each test suite in its own process, so if you have have say eight test suites running in parallel that means you'll have eight app processes running too.
When run, it will boot your app in the same process as the test suite and expose an interface for your tests to interact with it. Jest runs each test suite in its own process, so if you have say eight test suites running in parallel that means you'll have eight app processes running too.

Create a `tests/__helpers.ts` module with the following contents.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Now that you know a bit about Prisma, let's get going! Do the following:
like so:

```bash-symbol copy
npm add @prisma/client
npm add --save-dev prisma
npm install @prisma/client
npm install --save-dev prisma
```

Next, add Prisma to your project by creating your [Prisma schema](https://www.prisma.io/docs/concepts/components/prisma-schema/) file with the following command:
Expand Down Expand Up @@ -135,7 +135,7 @@ Now let's finally ditch our in-memory data! Let's replace it with the Prisma Cli
// api/db.ts
+import { PrismaClient } from '@prisma/client'

export const db = new PrismaClient()
+export const db = new PrismaClient()

-export interface Post {
- id: number
Expand Down Expand Up @@ -266,15 +266,15 @@ export const PostMutation = extendType({
draftId: nonNull(intArg()),
},
resolve(_root, args, ctx) {
- let postToPublish = ctx.db.posts.find((p) => p.id === args.draftId)
- let draftToPublish = ctx.db.posts.find((p) => p.id === args.draftId)

- if (!postToPublish) {
- if (!draftToPublish) {
- throw new Error('Could not find draft with id ' + args.draftId)
- }

- postToPublish.published = true
- draftToPublish.published = true

- return postToPublish
- return draftToPublish

+ return ctx.db.post.update({
+ where: { id: args.draftId },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To achieve some of the steps described above, we'll tweak our test context.
First, install the `sqlite3` and `nanoid` packages

```bash copy
npm add --save-dev sqlite3 @types/sqlite3
npm install --save-dev sqlite3 @types/sqlite3
```

Then, head to your `tests/__helpers.ts` file to add the following imports and code
Expand Down Expand Up @@ -220,7 +220,7 @@ function prismaTestContext() {
The `prismaTestContext` is in charge of a couple of things:

1. Connect to an in-memory instance of the SQLite database
2. Pushes the Prisma Schema to the adatabase
2. Pushes the Prisma Schema to the database
3. Generates a new Prisma Client
4. Add an instance of a Prisma Client connected to the schema specifically for the test

Expand Down
5 changes: 3 additions & 2 deletions docs/content/010-getting-started/04-why-nexus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Post = objectType({
const Query = queryType({
definition(t) {
t.list.field('posts', {
type: "Post",
resolve: () => [
{
id: '1',
Expand Down Expand Up @@ -93,7 +94,7 @@ There are numerous benefits to taking a code-first approach with Nexus:

When building a schema-first GraphQL API, it is common to start out by placing all type definitions and resolvers in a single file. When both the schema and the resolvers live next to one another, it's fairly straightforward to work in both at the same time.

As the application grows, however, it is most often desired to move parts of the schema into their own separate modules and files. It's at this point that working on a GraphQL API becomes a bit more tedious. With this modularization comes the need to switch back and forth between the Schema Definition Language and JavaScript/TypeScript to write the resolvers. Not only does one need to constantly switch between files, they also need to do a context switch mentally to work between the two langauges.
As the application grows, however, it is most often desired to move parts of the schema into their own separate modules and files. It's at this point that working on a GraphQL API becomes a bit more tedious. With this modularization comes the need to switch back and forth between the Schema Definition Language and JavaScript/TypeScript to write the resolvers. Not only does one need to constantly switch between files, they also need to do a context switch mentally to work between the two languages.

With Nexus, our schema and its resolvers are always defined together. Nexus also allows us to write everything in a common language. This allows us to side-step the co-location/context switching issue altogether and helps us to be more productive, even as our applications grow to be quite large.

Expand Down Expand Up @@ -133,7 +134,7 @@ A downside of the schema-first approach is the need to repeat yourself in schema

### Defining enums

When defining an enum using the schema-first approach, the enum must first be defined in the schema definition languange:
When defining an enum using the schema-first approach, the enum must first be defined in the schema definition language:

```graphql
enum UserRole {
Expand Down
28 changes: 24 additions & 4 deletions docs/content/015-api/050-input-object-type.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ codeStyle: true
Defines a complex object which can be passed as an input value.

```ts
export const InputType = inputObjectType({
name: 'InputType',
import { extendType, inputObjectType } from 'nexus'

export const CommentInputType = inputObjectType({
name: 'CommentInputType',
definition(t) {
t.nonNull.int('userId')
t.nonNull.string('body')
}
})

export const CommentMutation = extendType({
type: 'Mutation',
definition(t) {
t.nonNull.string('key')
t.int('answer')
t.field('createComment', {
type: 'Comment',
args: { data: CommentInputType },
resolve(_root, args, ctx) {
return ctx.prisma.comment.create({
data: {
user_id: args.userId,
body: args.body,
}
})
}
})
},
})
```
Expand Down
2 changes: 1 addition & 1 deletion docs/content/015-api/061-list-nonNull.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { queryType, stringArg, list } from 'nexus'
queryType({
definition(t) {
t.field('tags', {
type: list('String') // -> [String]
type: list('String'), // -> [String]
args: {
ids: list(stringArg()) // or list('String') -> [String]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/content/030-plugins/01-connection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Relay Connection

## Connection Plugin

The connection plugin provides a new method on the object definition builder, enabling paginated associations between types, following the [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm#sec-Node). It provides simple ways to customize fields available on the `Connection`, `Edges`, or `PageInfo` types.
The connection plugin provides a new method on the object definition builder, enabling paginated associations between types, following the [Relay Connection Specification](https://relay.dev/graphql/connections.htm#sec-Node). It provides simple ways to customize fields available on the `Connection`, `Edges`, or `PageInfo` types.

To install, add the `connectionPlugin` to the `makeSchema.plugins` array, along with any other plugins
you'd like to include:
Expand Down
4 changes: 2 additions & 2 deletions docs/content/030-plugins/050-prisma/010-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This plugin integrates [Prisma](https://www.prisma.io/) into [Nexus](https://nex
## Installation

```bash-symbol
npm add nexus-plugin-prisma @prisma/client
npm add -D prisma
npm install nexus-plugin-prisma @prisma/client
npm install -D prisma
```

## Usage
Expand Down
8 changes: 4 additions & 4 deletions docs/content/030-plugins/050-prisma/030-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ queryType({

type Query {
user(where: UserWhereUniqueInput!): User
users(orderBy: UserOrderByInput): [User!]!
users(orderBy: [UserOrderByInput!]): [User!]!
}

type Post {
Expand All @@ -1598,7 +1598,7 @@ type Post {
type User {
id: Int!
name: String!
posts(orderBy: UserPostsOrderByInput): [Post!]!
posts(orderBy: [UserPostsOrderByInput!]): [Post!]!
}

input UserOrderByInput {
Expand All @@ -1625,15 +1625,15 @@ enum OrderByArg {

```graphql
query entrypointOrdering {
users(orderBy: { name: asc }) {
users(orderBy: [{ name: asc }]) {
id
name
}
}

query relationOrdering {
user(where: { id: 1643 }) {
posts(orderBy: { title: dsc }) {
posts(orderBy: [{ title: desc }]) {
title
body
}
Expand Down
Loading

0 comments on commit c85898e

Please sign in to comment.