Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): revise nexus schema user migration guide #1259

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,40 @@ experimental: false
staticLink: false
---

## Migrate from Nexus Schema

Prior to version `0.20`, the `nexus` package comprised only the schema definition and code generation components of the Nexus framework. These components are now known as [`@nexus/schema`](../../components-standalone/schema), and while they're included as part of the Nexus framework, they remain available as a [standalone package](https://github.com/graphql-nexus/schema). (You can read more about the transition of Nexus from a schema library to a full-fledged framework in the [announcement in this GitHub issue](https://github.com/prisma-labs/nexus/issues/373).)

For users of `nexus` version `0.12` and below, you can either migrate to the `@nexus/schema` package, or to the new Nexus framework. The former is more straightforward, but the latter may significantly simplify your configuration and give you the benefit of baked-in sensible defaults and best practices (especially if you were previously using `graphql-yoga` or `express-graphql`). This guide will cover both scenarios.

## Using `@nexus/schema`

Run `npm rm nexus` and `npm i @nexus/schema` to migrate to the updated package name.

```json
+++ package.json
"dependencies": {
- "nexus": "0.12.0",
+ "@nexus/schema": "0.13.1"
}
```

Change any imports of `nexus` to `@nexus/schema`:

```ts
- import { makeSchema } from "nexus";
+ import { makeSchema } from "@nexus/schema";
```

If you are a `nexus-prisma` there is almost nothing extra to do. But note it has migrated to `nexus-plugin-prisma`. Learn more about the transition [here](https://github.com/graphql-nexus/nexus-plugin-prisma/issues/630). Do the following to keep using it:

Your Dependencies

```
npm remove nexus-prisma @prisma/client @prisma/cli
npm add nexus-plugin-prisma
```

Your Imports

```ts
- import { nexusPrismaPlugin } from 'nexus-prisma'
+ import { nexusSchemaPrisma } from 'nexus-plugin-prisma/schema'
```

## Using `nexus`
## Hello Nexus Schema User!

This guide is for you if you use `@nexus/schema` on a project and are curious about if you should upgrade to the framework and/or how.

Nexus is built on top of `@nexus/schema` adding many opinions and features. If you haven't you should check out the [tutorial](/getting-started/tutorial) and read the [introduction](/). But here's a quick rundown of the differences:

| feature | `nexus` | `@nexus/schema` |
| -------------------------------------------------------------------- | ------- | --------------- |
| JavaScript Support | ✖ | ✔ |
| `@nexus/schema` `makeSchema` Control | ✖ | ✔ |
| GraphQL Schema Builder API | ✔ | ✔ |
| Nexus Schema plugins | ✔ | ✔ |
| Zero Config | ✔ | ✖ |
| CLI | ✔ | ✖ |
| Development Mode | ✔ | ✖ |
| Integrated Build Step with Bundling | ✔ | ✖ |
| Builtin Server | ✔ | ✖ |
| Builtin Logger | ✔ | ✖ |
| Bundled Scalars | ✔ | ✖ |
| Type Discovery for Backing Types | ✔ | ✖ |
| Type Discovery for Context API | ✔ | ✖ |
| Module Discovery for Nexus modules | ✔ | ✖ |
| Framework Plugins | ✔ | ✖ |
| Bundled Dependencies ([why](https://nxs.li/why/bundle-dependencies)) | ✔ | ✖ |

## Migrating

### Dependencies

1. Remove `nexus@0.12` and add the latest `nexus` in its place (will be something greater than `0.20`).
1. Remove dependency `graphql` as `nexus` bundles it.
Remove `@nexus/schema` and add the latest `nexus` in its place. Also remove dependency `graphql` as `nexus` bundles it.

```json
+++ package.json
"dependencies": {
- "graphql": "...",
- "nexus": "0.12.0",
+ "nexus": "^0.24"
}
```
npm remove @nexus/schema graphql
npm add nexus
```

### Project Layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
title: Prisma Users
---

## Overview
## Hello Prisma User!

This guide is for you if you use `@prisma/client` on a project that _does not_ use Nexus but are wondering if you should.

Nexus is a feature rich GraphQL Framework. One of its hallmark features is how it helps you achieve a very high degree of type-safety as you implement your API. If you are a long-time Prisma user you can see it as a spiritual successor to the rich GraphQL experiences that Prisma 1 and even Graphcool offered. Nexus is still young, but growing fast.

If you haven't already, you should read the [Welcome to Nexus](/) introduction.

This guide will show you the ways you can use Nexus with the Prisma toolkit.

## Vanilla integration

As a Prisma user you can easily integrate Prisma into Nexus yourself, take a look:
Expand Down Expand Up @@ -44,13 +48,13 @@ This is fine, but there's something better. The Nexus Prisma _plugin_ (`nexus-pl
- Declarative APIs for projecting types from your Prisma schema onto your GraphQL Schema
- Declarative APIs for creating mutations and queries (including automatically implemented resolvers!)

If you haven't already, you should read the [Welcome to Nexus Prisma](../../plugins/prisma) introduction.
If you haven't already, you should read the [Welcome to Nexus Prisma](/pluginss/prisma) introduction.

## Learning Path

1. Read [Welcome to Nexus](/)
2. Do [The Nexus Tutorial](../../getting-started/tutorial/chapter-introduction)
3. If using the Prisma plugin (you should!) read [Welcome to Nexus Prisma](../../plugins/prisma)
3. If using the Prisma plugin (you should!) read [Welcome to Nexus Prisma](/pluginss/prisma)

TL;DR

Expand Down
47 changes: 47 additions & 0 deletions website/content/011-adoption-guides/030-nexus-0-12-users.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Nexus@0.12 Users
# TODO if these frontmatter items are removed the site crashes
duration: ''
experimental: false
staticLink: false
---

## Hello `nexus@0.12` or Lower User!

This guide is for you if you're a `nexus` user _prior_ to version `0.20`.

Prior to version `0.20`, the `nexus` package comprised only the schema component of the Nexus framework. The last version of this schema-only version of the `nexus` package was `0.12`. Subsequent versions moved to the package [`@nexus/schema`](../../components-standalone/schema). Meanwhile, `nexus` `0.20` and above became the framework package. It builds, in part, on top of `@nexus/schema`. You can read the announcement about the transition of Nexus from a schema library to a full-fledged framework in [this GitHub issue](https://github.com/graphql-nexus/schema/issues/373).)

You can remain a Nexus schema library user by using the `@nexus/schema` package. Or you can upgrade to the framework by using the latest version of the `nexus` package. The following sections show how to migrate either way.

## Migrating to `@nexus/schema`

Remove `nexus`, add `@nexus/schema` and update imports throughout your codebase accordingly. E.g.:

```
npm remove nexus
npm add @nexus/schema
```

```ts
- import { makeSchema } from "nexus";
+ import { makeSchema } from "@nexus/schema";
```

If you are a `nexus-prisma` user, note that the package has migrated to `nexus-plugin-prisma`. You can learn more about the transition in [this Github issue](https://github.com/graphql-nexus/nexus-plugin-prisma/issues/630).

To migrate, please remove `nexus-prisma`, `@prisma/client`, `@prisma/cli`, add `nexus-plugin-prisma`, and update imports throughout your codebase accordingly. E.g.:

```
npm remove nexus-prisma @prisma/client @prisma/cli
npm add nexus-plugin-prisma
```

```ts
- import { nexusPrismaPlugin } from 'nexus-prisma'
+ import { nexusSchemaPrisma } from 'nexus-plugin-prisma/schema'
```

## Migrating to `nexus` Framework

For this path, please refer to our [migration guide for Nexus Schema users](/adoption-guides/nexus-schema-users#migrating). The only difference is that instead of going from `@nexus/schema` to `nexus` you will be going from `nexus@0.12` (or lower) to `nexus@latest`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Migration guides
title: Adoption guides
hidePage: false
---

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ codeStyle: true

## queryField

Often times you want to split up query fields into different domains of your application, and like [`mutationField`](/components-standalone/schema/api/api-mutationField) are another one of the most common use-cases for `extendType`. `queryField` exists as a shorthand for this common case:
Often times you want to split up query fields into different domains of your application, and like [`mutationField`](/components-standalone/schema/api/api-mutation-field) are another one of the most common use-cases for `extendType`. `queryField` exists as a shorthand for this common case:

```ts
import { stringArg } from '@nexus/schema'
Expand Down Expand Up @@ -36,7 +36,7 @@ export const createUser = extendType({
})
```

You can also use it with a function as the first argument, which will pass the `t` provided to the definition block, especially useful when using with the [connection plugin](../plugins/connection):
You can also use it with a function as the first argument, which will pass the `t` provided to the definition block, especially useful when using with the [connection plugin](/components-standalone/schema/plugins/connection):

```ts
export const usersQueryField = queryField(t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Prisma

## Prisma

Refer to the [framework docs](../../../plugins/prisma#runtime-integration) for API reference and concepts. What follows here are aspects that are particular to the schema plugin only.
Refer to the [framework docs](/pluginss/prisma#runtime-integration-1) for API reference and concepts. What follows here are aspects that are particular to the schema plugin only.

## Installation

Expand Down