Skip to content

Commit

Permalink
Merge branch 'main' into tgriesser/feat/graphql-16
Browse files Browse the repository at this point in the history
* main:
  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)
  fix: Minimum GraphQL v16 support (#1017)
  chore(docs): add Example Code (#948)
  chore(docs): Update Ordering section (#950)
  chore(docs): Nexus Getting started: missing type in queryType (#995)
  chore(docs): readme update -- fix code sample to include ".ts" in module path (#998)
  chore(docs): typo fix in docs (#999)
  chore(docs): change package get-port ver in tutorial (#1000)
  docs: change all "npm add" to "npm install" (#991)
  docs: Update 061-list-nonNull.mdx (#986)
  feat: Add mergeSchema, better graphql-js interop (#983)
  refactor: More internal cleanup (#981)
  refactor: Internal type cleanup (#980)
  refactor: remove duplicate core schema type checks (#978)
  • Loading branch information
tgriesser committed Feb 14, 2022
2 parents e78ca06 + e901beb commit 2e51263
Show file tree
Hide file tree
Showing 46 changed files with 1,324 additions and 594 deletions.
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
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
20 changes: 10 additions & 10 deletions docs/content/040-adoption-guides/020-nexus-framework-users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You will need to manage the TypeScript toolchain yourself.
1. Install `typescript`, `ts-node`, and `ts-node-dev`.

```bash-symbol
npm add -D typescript ts-node ts-node-dev
npm install -D typescript ts-node ts-node-dev
```

2. The following applies to VSCode but something like it might apply to other editors as well. You must also make sure your editor is set to use the local version of TypeScript rather than the one the editor ships with. Summon the command pallet `command+shift+p` and then enter and select `typescript: select TypeScript Version...`. Then select `Workspace Version`.
Expand Down Expand Up @@ -205,13 +205,13 @@ Nexus framework comes bundled with Apollo Server and runs it for you. You will n
1. Install new dependencies

```tsx
npm add express apollo-server-express
npm install express apollo-server-express
```

2. If using TypeScript then Install typings for Express

```tsx
npm add -D @types/express
npm install -D @types/express
```

3. If using TypeScript then you [need to](https://github.com/apollographql/apollo-server/issues/1977#issuecomment-662946590) enable `esModuleInterop` to be able to use Apollo Server
Expand Down Expand Up @@ -337,7 +337,7 @@ Nexus Framework has some builtin logging functionality. You can approximate it a
1. Install your logger
```tsx
npm add floggy
npm install floggy
```
2. Create your application logger. The logger you export here should be used across your codebase.
Expand Down Expand Up @@ -386,7 +386,7 @@ You need to explicitly setup all custom scalars yourself. To match what Nexus Fr
1. Install the `graphql-scalars` package
```json
npm add graphql-scalars
npm install graphql-scalars
```
2. Setup the `Json` and `DateTime` scalars
Expand Down Expand Up @@ -448,7 +448,7 @@ import * as Path from 'path'

Nexus.makeSchema({
contextType: {
module: Path.join(__dirname, './path/to/contextModule'),
module: Path.join(__dirname, './path/to/contextModule.ts'),
alias: 'ContextModule',
export: 'Context'
},
Expand Down Expand Up @@ -536,13 +536,13 @@ In Nexus Framework there was a testing module for system testing your app. You n
1. Install your test framework
```tsx
npm add jest
npm install jest
```
2. If you are a TypeScript user then install and configure `ts-jest`
```bash
npm add ts-jest
npm install ts-jest
```
We will configure using a `jest.config.js` module in your project root. Do not use a JSON based configuration unless you know that you won't need the dynamic code used in some later steps here.
Expand Down Expand Up @@ -639,7 +639,7 @@ In Nexus Framework there was a testing module for system testing your app. You n
6. You will need a way to run your app in tests. Here is one way [adapted from the tutorial](https://todo.com).
```tsx
npm add -D graphql-request
npm install -D graphql-request
```
```tsx
Expand Down Expand Up @@ -688,7 +688,7 @@ Nexus Framework had a CLI for scaffolding new projects. You can approximate this
Nexus Framework has a gradual settings API with features such as automatic mapping of environment variables to settings. You can use the [`setset`](https://github.com/jasonkuhrt/setset) package manually to gain back this functionality.
```tsx
npm add setset
npm install setset
```
```tsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ If you're looking to migrate from the Nexus Framework over to Nexus and you're u
You will need to install the Prisma dependencies yourself now.

```
npm add -D @prisma/cli
npm add @prisma/client
npm install -D @prisma/cli
npm install @prisma/client
```

You must also make sure that you are using the version `0.20` or later of `nexus-plugin-prisma`.
Expand Down Expand Up @@ -82,7 +82,7 @@ export const schema = makeSchema({

### Configuring Context Type

The framework used to automatically inject and type your context so that an instance of the client would be there for you. We know need to configure that manually. To do so, we'll first create a `context.ts` file where we'll export a type containing the Prisma Client.
The framework used to automatically inject and type your context so that an instance of the client would be there for you. We now need to configure that manually. To do so, we'll first create a `context.ts` file where we'll export a type containing the Prisma Client.

```tsx
// context.ts
Expand Down Expand Up @@ -128,7 +128,7 @@ If your Prisma Schema is using either the `Json` or `DateTime` type, the framewo

```bash
npm install graphql-scalars
```
```xf
2. Then, add the following configuration property to the Prisma plugin
Expand Down
4 changes: 2 additions & 2 deletions docs/content/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Check out the [example projects](https://github.com/graphql-nexus/nexus/tree/mai
## Installation

```sh
npm add nexus
npm add graphql # required as a peer dependency
npm install nexus
npm install graphql # required as a peer dependency
```

If you are using TypeScript version `4.1` is suggested. Nexus doesn't have a hard requirement for it yet but may in a future non-breaking release.
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"release:pr": "dripip pr",
"release:preview": "dripip preview",
"release:stable": "dripip stable",
"pretest": "yarn patch-package",
"test": "yarn test:types && jest --testTimeout 10000",
"test:ci": "yarn test:types && jest --maxWorkers 2 --coverage --testTimeout 10000",
"test:debug": "node --inspect-brk $(yarn bin)/jest -i --watch",
Expand Down Expand Up @@ -92,7 +91,6 @@
"jest": "^26.6.3",
"jest-watch-typeahead": "^0.6.1",
"lint-staged": "^7.3.0",
"patch-package": "6.2.2",
"prettier": "^2.3.1",
"sort-package-json": "^1.22.1",
"ts-jest": "^26.4.4",
Expand Down
Loading

0 comments on commit 2e51263

Please sign in to comment.