Skip to content

Commit 6f53694

Browse files
committed
Merge branch 'master' into feat/better-modules-import
2 parents e3749f4 + 6607c9a commit 6f53694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1606
-579
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ yarn-error.log*
5353

5454
.DS_Store
5555
.vscode
56-
dist
57-
tsconfig.tsbuildinfo
56+
dist*
57+
*.tsbuildinfo
5858

5959
.now
6060

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
- Meta
4242

43+
- [Roadmap ⤤](https://github.com/orgs/graphql-nexus/projects/1)
4344
- [Changelog](changelog)
4445
- [Architecture](architecture)
4546

docs/api/modules/main.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ app.schema.queryType({
1818
t.field('foo', { type: 'String' })
1919
},
2020
})
21-
22-
app.server.start()
2321
```
2422

2523
**Example of imporrting named exports**
2624

2725
```ts
28-
import { schema, server, settings, log } from 'nexus'
26+
import { schema, settings, log } from 'nexus'
2927

3028
log.info('hello world')
3129

@@ -40,6 +38,4 @@ schema.queryType({
4038
t.field('foo', { type: 'String' })
4139
},
4240
})
43-
44-
server.start()
4541
```

docs/api/modules/main/exports/schema.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,49 @@ schema.queryType({
10551055
*/
10561056
```
10571057

1058+
### `importType`
1059+
1060+
##### Signature
1061+
1062+
```ts
1063+
(scalarType: GraphQLScalarType, methodName?: string): GraphQLScalarType
1064+
(type: GraphQLNamedType): GraphQLNamedType
1065+
```
1066+
1067+
`schema.importType` is useful for adding existing GraphQL.js types into your Nexus schema.
1068+
1069+
[Check out this repository](https://github.com/Urigo/graphql-scalars) for a handful list of useful scalar types that might be useful to your GraphQL API.
1070+
1071+
When passing a `GraphQLScalarType`, you can additionally pass a `methodName` as a second parameter, which will augment the `t` parameter of your definition builder with a convenient method to create a field of the associated type.
1072+
1073+
##### Example: Adding a date scalar type
1074+
1075+
```ts
1076+
import { schema } from 'nexus'
1077+
import { GraphQLDate } from 'graphql-iso-date'
1078+
1079+
schema.importType(GraphQLDate, 'date')
1080+
1081+
schema.objectType({
1082+
name: 'SomeObject',
1083+
definition(t) {
1084+
t.date('createdAt') // t.date() is now available (with types!) thanks to `importType`
1085+
},
1086+
})
1087+
```
1088+
1089+
`schema.importType` can also be used to add types from an existing GraphQL schema into your Nexus schema. This is useful to incrementally adopt Nexus if you already have a GraphQL schema built with a different technology than Nexus.
1090+
1091+
##### Example: Adding types from a schema-first schema
1092+
1093+
```ts
1094+
import { schema } from 'nexus'
1095+
import { existingSchema } from './existing-schema'
1096+
1097+
1098+
Object.values(existingSchema.getTypeMap()).forEach(schema.importType)
1099+
```
1100+
10581101
### Type Glossary
10591102

10601103
#### `I` `FieldConfig`

docs/api/modules/testing.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ This context can be augmented by plugins.
1212
function createTestContext(opts?: CreateTestContextOptions): Promise<TestContext>
1313
```
1414

15-
1615
##### Example With Jest
1716

1817
```ts
19-
import { } from 'nexus/testing'
18+
import { TestContext, createTestContext } from 'nexus/testing'
2019
2120
let ctx: TestContext
2221
2322
beforeAll(async () => {
24-
ctx = await createTestContext()
25-
await ctx.server.start()
23+
Object.assign(ctx, await createTestContext())
24+
await ctx.app.start()
2625
})
2726
2827
afterAll(async () => {
29-
await ctx.server.stop()
28+
await ctx.app.stop()
3029
})
3130
3231
test('hello', async () => {

docs/architecture.md

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,91 @@ todo
66

77
todo
88

9+
## Plugins
10+
11+
### Diagrams
12+
13+
#### Plugin Tree Shaking
14+
15+
![plugin-tree-shaking](https://dsc.cloud/661643/plugin-tree-shaking.png)
16+
17+
### Glossary
18+
19+
#### Entrypoint
20+
21+
A plugin entrypoint is responsible for returning the plugin's manifest input. This is what users actually deal with at the app layer.
22+
23+
```ts
24+
import { prisma } from 'nexus-plugin-prisma'
25+
// ~~~~~~ <------------- The entrypoint, returns a manifest input
26+
import { use } from 'nexus'
27+
28+
use(prisma())
29+
```
30+
31+
#### Manifest
32+
33+
A plugin manifest describes logistical information about a plugin like where its package file is located on disk, what versions of Nexus it is compatible with, and more.
34+
35+
Plugin manifests are created by Nexus by processing the manifest inputs returned by plugin entrypoints.
36+
37+
```ts
38+
import { prisma } from 'nexus-plugin-prisma'
39+
40+
const prismaPluginManifestInput = prisma()
41+
```
42+
43+
This lazy approach allows Nexus the flexibility it needs to provide features like automatic environment variable plugin settings injection and tree-shaking.
44+
45+
#### Manifest Input
46+
47+
A manifest input is the view of manifests that plugin authors work with. It models the minimum information that Nexus needs to build the plugin manifest. It is also more human friendly, for example minimizing the number of required fields. Developer experience is not the primary motivation here however. We want Nexus to control as much as possible, so the less the human has to specify the more we achieve this goal. For example we ask for a path to package json rather than the contents of it. We want Nexus to be the one that reads it, when and how it wants.
48+
49+
#### Dimension
50+
51+
A plugin dimension represents a high-level area of plugin concern that are separated by module from other dimensions. In other words, each dimension has its own entrypoint. Nexus will directly import it. A dimension is found by Nexus from Nexus reading the Plugin manifest.
52+
53+
There are three dimensions: worktime, testtime, and runtime. Worktime allows plugins to tap into the CLI, the builder, dev mode, and more. Testtime allows plugins to tap into features of the Nexus testing component. Runtime allows plugins to tap into the API.
54+
55+
Directionally Nexus is on a good track, but there is work still left to do. The names are a bit confusing when you dig into the details, and the supposed separation between worktime/runtime has undesirable "loopholes" because of reflection. Details;
56+
57+
1. Runtime dimension does not mean plugging exclusively into what is run in your production code. There are actually reasons to plug into the runtime for ostensibly worktime beneit... This is due to Nexus' so-called reflection system, wherein the app is run in the background during development for development purposes.
58+
59+
2. The rationale for splitting worktime from runtime is clear, tree-shaking alone makes the case for it. However the separation between worktime and testing is less clear, perhaps nonsense, and so may be revisited in the future.
60+
61+
3. We've talked about motivation for separating worktime from runtime, yet there are runtime parts for worktime (reflection). What this means is that expensive dependencies can make there way into the runtime dimension that a user should actually _not_ be paying for in production runtime.
62+
63+
#### Lens
64+
65+
A plugin lens is just a specialized api into a subset of Nexus to hook into, extend, manipulate, and react to it during execution. The name "lens" is arbitrary. The choice comes from it being "view" into Nexus. Each dimension has its own specialized lens.
66+
67+
#### Dimension Entrypoint
68+
69+
Just like the plugin has a top level entrypoint so to does each dimension within the plugin have its own entrypoint. These sub-entrypoints can be thought as sub-plugins, with the top-level plugin just being a grouping mechanism.
70+
71+
### Comparisons to Other Systems
72+
73+
#### Rollup
74+
75+
- Like Rollup plugins are prefixed with `<tool-name>-plugin-<plugin-name>`
76+
- We have considered but so far not put first-party Nexus plugins under the pattern `@nexus/plugin-<plugin-name>`. Rollup made this transition retroactively.
77+
- Rollup suggests plugins have a default export so that are much easier to use on the command line. Nexus suggests plugins also have default exports for similar system-usability reasons (not cli in Nexus' case, but other future features maybe like auto-use).
78+
79+
### Loading Flow
80+
81+
todo
82+
what follows is a stub
83+
84+
1. capture the used plugins in the app
85+
1. validate entrypoints
86+
1. transform entrypoints into manifests
87+
1. for each dimension (work, test, run) in the manifest
88+
1. import it
89+
1. catch any import errors
90+
1. validate imported value
91+
1. load plugin
92+
1. catch any load errors
93+
994
## Build Flow
1095

1196
1. The app layout is calculated
@@ -25,27 +110,12 @@ todo
25110
1. A new TypeScript instance is created so that the types generated in the previous step are picked up by the checker. This should be faster because it reuses the TypeScript cache created in the previous step.
26111
1. The app is type checked
27112
1. The app is transpiled
28-
1. The app is emitted into `node_modules/.build`. This convention keeps derived files in a well known generally ignored location.
113+
1. The app is emitted into `.nexus/build`. This convention keeps derived files in a well known generally ignored location.
29114
1. A production-oriented start module is generated differing in the following ways:
30115
- paths are relative
31116
- typescript not hooked into module extensions
32117
- plugins are imported for tree-shaking
33118

34-
## Plugin Loading Flow
35-
36-
todo
37-
what follows is a stub
38-
39-
1. capture the used plugins in the app
40-
1. validate entrypoints
41-
1. transform entrypoints into manifests
42-
1. for each dimension (work, test, run) in the manifest
43-
1. import it
44-
1. catch any import errors
45-
1. validate imported value
46-
1. load plugin
47-
1. catch any load errors
48-
49119
## Glossary
50120

51121
### Assembly

docs/community/roadmap.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/components/schema/api/_sidebar.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
- Plugins
2323

2424
- [`prisma`](plugins/prisma)
25+
- [`jwt-auth`](https://github.com/Camji55/nexus-plugin-jwt-auth)
26+
- [`graphql-shield`](https://github.com/lvauvillier/nexus-plugin-shield)
2527

26-
- API
28+
* API
2729

28-
- [`nexus`](api/modules/main)
30+
* [`nexus`](api/modules/main)
2931

3032
- [`schema`](api/modules/main/exports/schema)
3133
- [`log`](api/modules/main/exports/logger)
@@ -35,11 +37,17 @@
3537

3638
- [`nexus/testing`](api/modules/testing)
3739

38-
* [`nexus/plugin`](api/modules/plugin)
40+
- [`nexus/plugin`](api/modules/plugin)
3941

40-
- Components Standalone
42+
- Meta
4143

42-
- [`@nexus/schema`](components/schema/about)
44+
- [Roadmap ⤤](https://github.com/orgs/graphql-nexus/projects/1)
45+
- [Changelog](changelog)
46+
- [Architecture](architecture)
47+
48+
* Components Standalone
49+
50+
* [`@nexus/schema`](components/schema/about)
4351

4452
- [API](components/schema/api/index.md)
4553
- [objectType](components/schema/api/copy/api-objectType)

docs/getting-started/migrate-from-nexus-schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ You should only be working with the `nexus` CLI. Below shows the example scripts
108108
- "dev": "ts-node-dev --no-notify --respawn --transpileOnly src/server",
109109
+ "dev": "nexus dev",
110110
+ "build": "nexus build",
111-
+ "start": "node node_modules/.build"
111+
+ "start": "node .nexus/build"
112112
},
113113
```
114114

docs/getting-started/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> For this tutorial we will use PostgreSQL as our database. Install PostgreSQL if needed and then get its connection URL. Check out [our postgresql setup guide](references/recipes?id=local-postgresql) if unsure.
1+
> For this tutorial we will use PostgreSQL as our database. Install PostgreSQL if needed and then get its connection URL. Check out [our postgresql setup guide](references/recipes?id=localql) if unsure.
22
33
## Scaffold Project
44

docs/guides/project-layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
- Out Root is the place where the transpiled TypeScript (to JavaScript) modules will be emitted to. The folder structure mimicks that of the source root.
2323
- Out Root is defined by setting `compilerOptions.outDir`.
24-
- If you do not specify it then Nexus will default to `node_modules/.build`. Unlike with `rootDir` Nexus will not scaffold the default into your `tsconfig.json` because its presence has no impact upon VSCode.
24+
- If you do not specify it then Nexus will default to `.nexus/build`. Unlike with `rootDir` Nexus will not scaffold the default into your `tsconfig.json` because its presence has no impact upon VSCode.
2525
- You can override its value interactively with `nexus build --out`.
2626

2727
##### Check-Only Builds

docs/guides/serverless.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
}
2121
```
2222

23-
- See the [Next.JS example](https://github.com/graphql-nexus/examples/tree/master/integration-nextjs) for a functioning serverless reference.
23+
- See the [Next.JS example](https://github.com/graphql-nexus/examples/tree/master/with-nextjs) for a functioning serverless reference.

docs/guides/testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export function createTestContext(): TestContext {
2424

2525
beforeAll(async () => {
2626
Object.assign(ctx, await originalCreateTestContext())
27-
await ctx.app.server.start()
27+
await ctx.app.start()
2828
})
2929

3030
afterAll(async () => {
31-
await ctx.app.server.stop()
31+
await ctx.app.stop()
3232
})
3333

3434
return ctx
@@ -88,7 +88,7 @@ Integration testing with a database can add a lot of complexity to your test sui
8888

8989
Integration between Nexus' test and database systems is young and still missing many features. Below we will cover some utilities and patterns that you can copy into your project meanwhile.
9090

91-
> Note: This assumes you have [setup a PostgreSQL database running locally](references/recipes?id=local-postgresql). You could use any database supported by Prisma though.
91+
> Note: This assumes you have [setup a PostgreSQL database running locally](references/recipes?id=localql). You could use any database supported by Prisma though.
9292
9393
1. Install new development dependencies for upcoming test utilities.
9494

docs/plugins/prisma.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ schema.queryType({
219219
},
220220
})
221221

222-
schema.schema.mutationType({
222+
schema.mutationType({
223223
definition(t) {
224224
t.crud.createOneUser()
225225
t.crud.createOnePost()

0 commit comments

Comments
 (0)