Skip to content

Commit 00628c9

Browse files
committed
fix all docs to SchemaRoot instead of Schema
1 parent edcf526 commit 00628c9

File tree

18 files changed

+67
-62
lines changed

18 files changed

+67
-62
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ query {
3434
```
3535

3636
```ts
37-
import { Schema, Query, compileSchema } from 'decapi'
37+
import { SchemaRoot, Query, compileSchema } from 'decapi'
3838

39-
@Schema()
39+
@SchemaRoot()
4040
class SuperSchema {
4141
@Query()
4242
hello(name: string): string {
@@ -87,7 +87,7 @@ Such query will have a bit more code and here it is:
8787

8888
```ts
8989
import {
90-
Schema,
90+
SchemaRoot,
9191
Query,
9292
ObjectType,
9393
Field,
@@ -109,7 +109,7 @@ class Product {
109109
}
110110
}
111111

112-
@Schema()
112+
@SchemaRoot()
113113
class SuperSchema {
114114
@Mutation()
115115
createProduct(name: string, price: number): Product {

docs/explore/duplex-type-and-duplex-field.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class User {
2020
password_hash: string
2121
}
2222

23-
@Schema()
23+
@SchemaRoot()
2424
class SuperSchema {
2525
@Mutation()
2626
createUser(data: User): User {

docs/explore/schema/Schema.mdx

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ decapi is set of decorators allowing creating GraphQL APIs quickly and in type-s
1313

1414
Schema is main building block of any `graphql` schema. It'll join all parts of our api together.
1515

16-
In `decapi` to create schema, we need to pass a class decorated with `@Schema` to `compileSchema` function
16+
In `decapi` to create schema, we need to pass a class decorated with `@SchemaRoot` to `compileSchema` function
1717

1818
```js
19-
import { Schema, compileSchema} from 'decapi
19+
import { SchemaRoot, compileSchema} from 'decapi
2020
21-
@Schema()
21+
@SchemaRoot()
2222
class SuperSchema {
2323
// fields implementation
2424
}
@@ -28,7 +28,7 @@ const compiledSchema = compileSchema(SuperSchema);
2828
2929
`compiledSchema` from example above is standard, regular `graphql` schema.
3030
31-
You can also pass an array of classes decorated with `@Schema`-any non trivial app will probably require more than one class to expose all it's API root logic.
31+
You can also pass an array of classes decorated with `@SchemaRoot`-any non trivial app will probably require more than one class to expose all it's API root logic.
3232

3333
## Adding Query and Mutation fields
3434

@@ -45,9 +45,9 @@ Very simple fully working schema like
4545
Could be implemented as:
4646

4747
```js
48-
import { Schema, Query, compileSchema} from 'decapi
48+
import { SchemaRoot, Query, compileSchema} from 'decapi
4949
50-
@Schema()
50+
@SchemaRoot()
5151
class SuperSchema {
5252
@Query()
5353
hello(): string {
@@ -71,9 +71,9 @@ Let's add some customization to our schema:
7171
With tiny change in our code:
7272
7373
```js
74-
import { Schema, Query, compileSchema} from 'decapi
74+
import { SchemaRoot, Query, compileSchema} from 'decapi
7575

76-
@Schema()
76+
@SchemaRoot()
7777
class SuperSchema {
7878
@Query()
7979
hello(name: string): string {
@@ -101,7 +101,7 @@ mutation {
101101
Such query will have a bit more code and here it is:
102102

103103
```js
104-
import { Schema, Query, ObjectType, Field, Mutation, compileSchema} from 'decapi;
104+
import { SchemaRoot, Query, ObjectType, Field, Mutation, compileSchema} from 'decapi;
105105
106106
@ObjectType({ description: 'Simple product object type' })
107107
class Product {
@@ -117,7 +117,7 @@ class Product {
117117
}
118118
}
119119
120-
@Schema()
120+
@SchemaRoot()
121121
class SuperSchema {
122122
@Mutation()
123123
createProduct(name: string, price: number): Product {

docs/getting-started/minimal-example.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Schema able to handle such query:
1919
Can be created with:
2020

2121
```ts
22-
import { Schema, Query, ObjectType, Field, compileSchema } from 'decapi'
22+
import { SchemaRoot, Query, ObjectType, Field, compileSchema } from 'decapi'
2323

2424
@ObjectType()
2525
class Hello {
@@ -29,7 +29,7 @@ class Hello {
2929
}
3030
}
3131

32-
@Schema()
32+
@SchemaRoot()
3333
class MyFirstSchema {
3434
@Query()
3535
hello(): Hello {

docs/reference/api-reference.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,23 @@ type HookExecutor = (data: HookExecutorResolverArgs) => any | Promise<any>;
187187
@After(hook: HookExecutor);
188188
```
189189
190-
## @Schema
190+
## @SchemaRoot
191191
192192
```ts
193-
@Schema(): ClassDecorator;
193+
@SchemaRoot(): ClassDecorator;
194194
```
195195
196196
### @Query
197197
198-
Has same interface as [@Field](#field) decorator. Can be used only inside @Schema class
198+
Has same interface as [@Field](#field) decorator. Can be used only inside @SchemaRoot class
199199
200200
### @Mutation
201201
202-
Has same interface as [@Field](#field) decorator. Can be used only inside @Schema class
202+
Has same interface as [@Field](#field) decorator. Can be used only inside @SchemaRoot class
203203
204204
### @QueryAndMutation
205205
206-
A shorthand for both Query And Mutation. Can be used only inside @Schema class
206+
A shorthand for both Query And Mutation. Can be used only inside @SchemaRoot class
207207
208208
## @Union
209209

examples/basic-express-server/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Here is all the server code required:
1212

1313
```ts
1414
import express from 'express'
15-
import { Schema, Query, compileSchema } from 'decapi'
15+
import { SchemaRoot, Query, compileSchema } from 'decapi'
1616
import graphqlHTTP from 'express-graphql'
1717

18-
@Schema()
18+
@SchemaRoot()
1919
class SuperSchema {
2020
@Query()
2121
hello(name: string): string {

examples/custom-decorators/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Doing it is quite simple. You'd need to define custom function that returns call
77
Let's say we want to define custom field decorator that always has `String` type and requires field description (that originally would be optional)
88

99
```ts
10-
import { Schema, Query, Field, ObjectType, compileSchema } from 'decapi'
10+
import { SchemaRoot, Query, Field, ObjectType, compileSchema } from 'decapi'
1111

1212
function StringWithDescription(fieldDescription: string) {
1313
if (!fieldDescription) {

examples/custom-decorators/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import express from 'express'
2-
import { Schema, Query, compileSchema } from 'decapi'
32
import graphqlHTTP from 'express-graphql'
43

54
import { schema } from './schema'

examples/serverless/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ query {
1313
As schema compiled by `compileSchema` is regular, normal GraphQLSchema, we can simply use it with `apollo-server-lambda` that will handle everything.
1414

1515
```ts
16-
import { Schema, Query, compileSchema } from 'decapi'
16+
import { SchemaRoot, Query, compileSchema } from 'decapi'
1717
import { graphqlLambda, graphiqlLambda } from 'apollo-server-lambda'
1818

19-
@Schema()
19+
@SchemaRoot()
2020
class MySchema {
2121
@Query()
2222
hello(name: string): string {

examples/typeorm-basic-integration/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class User extends BaseEntity {
7171
After model is ready, let's define some api interface with some mutation and queries
7272

7373
```ts
74-
@Schema()
74+
@SchemaRoot()
7575
class ApiSchema {
7676
@Query({ type: [User] }) // as function return type is Promise of user, we need to set type manually as array of users
7777
async getAllUsers(): Promise<User[]> {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
"rimraf": "^3.0.0",
5656
"rollup": "^1.21.0",
5757
"rollup-plugin-typescript2": "^0.24.0",
58-
"ts-jest": "^24.0.2",
58+
"ts-jest": "^24.1.0",
5959
"tslint": "^5.19.0",
6060
"tslint-config-prettier": "^1.18.0",
6161
"tslint-sonarts": "^1.9.0",
62-
"typescript": "^3.6.2"
62+
"typescript": "^3.6.3"
6363
},
6464
"peerDependencies": {
6565
"graphql": "^0.13 || ^14"

src/domains/field/compiler/fieldCompiler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function getAllFields(target: Function) {
6262
throw new FieldError(
6363
target,
6464
fieldName,
65-
`Given field is root field (@Query or @Mutation) not registered inside @Schema type. `
65+
`Given field is root field (@Query or @Mutation) not registered inside @SchemaRoot type. `
6666
)
6767
}
6868

src/domains/field/special-fields.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ObjectType, Query, compileObjectType } from '../..'
22

33
describe('Special fields - @Query, @Mutation @Subscribe', () => {
4-
it('Will not allow registering special type on type that is not @Schema', () => {
4+
it('Will not allow registering special type on type that is not @SchemaRoot', () => {
55
@ObjectType()
66
class Foo {
77
@Query()
@@ -13,7 +13,7 @@ describe('Special fields - @Query, @Mutation @Subscribe', () => {
1313
expect(() => {
1414
return compileObjectType(Foo).getFields()
1515
}).toThrowErrorMatchingInlineSnapshot(
16-
`"@ObjectType Foo.bar: Given field is root field (@Query or @Mutation) not registered inside @Schema type. "`
16+
`"@ObjectType Foo.bar: Given field is root field (@Query or @Mutation) not registered inside @SchemaRoot type. "`
1717
)
1818
})
1919
})

src/domains/schema/SchemaRoot.spec.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ import {
1717
} from 'graphql'
1818

1919
describe('@SchemaRoot', () => {
20-
it('should not allow compiling schema not decorated with @Schema', () => {
20+
it('should not allow compiling schema not decorated with @SchemaRoot', () => {
2121
class Foo {}
2222

23-
expect(() => compileSchema([Foo])).toThrowErrorMatchingSnapshot()
23+
expect(() => compileSchema([Foo])).toThrowErrorMatchingInlineSnapshot(
24+
`"@SchemaRoot Foo: Schema root must be registered with @SchemaRoot"`
25+
)
2426
})
2527

26-
it('should not allow @Schema without any @Query field', () => {
28+
it('should not allow @SchemaRoot without any @Query field', () => {
2729
@SchemaRoot()
2830
class Foo {}
2931

30-
expect(() => compileSchema([Foo])).toThrowErrorMatchingSnapshot()
32+
expect(() => compileSchema([Foo])).toThrowErrorMatchingInlineSnapshot(
33+
`"At least one of schema roots must have @Query root field."`
34+
)
3135
})
3236

3337
it('should generate all schema fields properly for valid schema', async () => {
@@ -133,7 +137,9 @@ describe('@SchemaRoot', () => {
133137

134138
expect(() =>
135139
compileSchema([FooSchema, BarSchema])
136-
).toThrowErrorMatchingSnapshot()
140+
).toThrowErrorMatchingInlineSnapshot(
141+
`"At least one of schema roots must have @Query root field."`
142+
)
137143
})
138144

139145
it('will not allow multiple schema roots to have conflicting root field names', async () => {
@@ -155,7 +161,9 @@ describe('@SchemaRoot', () => {
155161

156162
expect(() =>
157163
compileSchema([FooSchema, BarSchema])
158-
).toThrowErrorMatchingSnapshot()
164+
).toThrowErrorMatchingInlineSnapshot(
165+
`"@SchemaRoot BarSchema: Duplicate of root field name: 'foo'. Seems this name is also used inside other schema root."`
166+
)
159167
})
160168

161169
it('will not allow schema with incorrect object types', async () => {
@@ -175,7 +183,9 @@ describe('@SchemaRoot', () => {
175183
}
176184
}
177185

178-
expect(() => compileSchema([FooSchema])).toThrowErrorMatchingSnapshot()
186+
expect(() => compileSchema([FooSchema])).toThrowErrorMatchingInlineSnapshot(
187+
`"@ObjectType Hello.world: Field type was infered as \\"function Promise() { [native code] }\\" so it's required to explicitly set the type as it's not possible to guess it. Pass it in a config for the field like: @Field({ type: ItemType })"`
188+
)
179189
})
180190

181191
it('should support schema root instance properties', async () => {

src/domains/schema/__snapshots__/SchemaRoot.spec.ts.snap

-10
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,3 @@ In some cases, you need to provide options to alter GraphQL's execution behavior
968968
},
969969
}
970970
`;
971-
972-
exports[`@SchemaRoot should not allow @Schema without any @Query field 1`] = `"At least one of schema roots must have @Query root field."`;
973-
974-
exports[`@SchemaRoot should not allow compiling schema not decorated with @Schema 1`] = `"@Schema Foo: Schema root must be registered with @SchemaRoot"`;
975-
976-
exports[`@SchemaRoot should not allow schema that has only mutation fields 1`] = `"At least one of schema roots must have @Query root field."`;
977-
978-
exports[`@SchemaRoot will not allow multiple schema roots to have conflicting root field names 1`] = `"@Schema BarSchema: Duplicate of root field name: 'foo'. Seems this name is also used inside other schema root."`;
979-
980-
exports[`@SchemaRoot will not allow schema with incorrect object types 1`] = `"@ObjectType Hello.world: Field type was infered as \\"function Promise() { [native code] }\\" so it's required to explicitly set the type as it's not possible to guess it. Pass it in a config for the field like: @Field({ type: ItemType })"`;

src/domains/schema/error.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { BaseError } from '../../services/error'
22

33
export class SchemaRootError extends BaseError {
44
constructor(target: Function, msg: string) {
5-
const fullMsg = `@Schema ${target.name}: ${msg}`
5+
const fullMsg = `@SchemaRoot ${target.name}: ${msg}`
66
super(fullMsg)
77
this.message = fullMsg
88
}
99
}
1010

1111
export class SchemaFieldError extends BaseError {
1212
constructor(target: Function, fieldName: string, msg: string) {
13-
const fullMsg = `@Schema ${target.name}.${fieldName}: ${msg}`
13+
const fullMsg = `@SchemaRoot ${target.name}.${fieldName}: ${msg}`
1414
super(fullMsg)
1515
this.message = fullMsg
1616
}

src/domains/schema/rootFields.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function requireSchemaRoot(target: Function, fieldName: string) {
2626
throw new SchemaFieldError(
2727
target,
2828
fieldName,
29-
`Root field must be registered on class decorated with @Schema`
29+
`Root field must be registered on class decorated with @SchemaRoot`
3030
)
3131
}
3232

yarn.lock

+14-8
Original file line numberDiff line numberDiff line change
@@ -6638,6 +6638,11 @@ lodash.iteratee@^4.5.0:
66386638
resolved "https://registry.yarnpkg.com/lodash.iteratee/-/lodash.iteratee-4.7.0.tgz#be4177db289a8ccc3c0990f1db26b5b22fc1554c"
66396639
integrity sha1-vkF32yiajMw8CZDx2ya1si/BVUw=
66406640

6641+
6642+
version "4.1.2"
6643+
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
6644+
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
6645+
66416646
lodash.sortby@^4.7.0:
66426647
version "4.7.0"
66436648
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
@@ -10153,15 +10158,16 @@ tryer@^1.0.1:
1015310158
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
1015410159
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
1015510160

10156-
ts-jest@^24.0.2:
10157-
version "24.0.2"
10158-
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d"
10159-
integrity sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw==
10161+
ts-jest@^24.1.0:
10162+
version "24.1.0"
10163+
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.1.0.tgz#2eaa813271a2987b7e6c3fefbda196301c131734"
10164+
integrity sha512-HEGfrIEAZKfu1pkaxB9au17b1d9b56YZSqz5eCVE8mX68+5reOvlM93xGOzzCREIov9mdH7JBG+s0UyNAqr0tQ==
1016010165
dependencies:
1016110166
bs-logger "0.x"
1016210167
buffer-from "1.x"
1016310168
fast-json-stable-stringify "2.x"
1016410169
json5 "2.x"
10170+
lodash.memoize "4.x"
1016510171
make-error "1.x"
1016610172
mkdirp "0.x"
1016710173
resolve "1.x"
@@ -10268,10 +10274,10 @@ [email protected]:
1026810274
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.4000.tgz#76b0f89cfdbf97827e1112d64f283f1151d6adf0"
1026910275
integrity sha512-jjOcCZvpkl2+z7JFn0yBOoLQyLoIkNZAs/fYJkUG6VKy6zLPHJGfQJYFHzibB6GJaF/8QrcECtlQ5cpvRHSMEA==
1027010276

10271-
typescript@^3.6.2:
10272-
version "3.6.2"
10273-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.2.tgz#105b0f1934119dde543ac8eb71af3a91009efe54"
10274-
integrity sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==
10277+
typescript@^3.6.3:
10278+
version "3.6.3"
10279+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da"
10280+
integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==
1027510281

1027610282
ua-parser-js@^0.7.18:
1027710283
version "0.7.20"

0 commit comments

Comments
 (0)