diff --git a/examples/extend.ts b/examples/extend.ts new file mode 100644 index 0000000..79d02a8 --- /dev/null +++ b/examples/extend.ts @@ -0,0 +1,45 @@ +import { g, Infer, InferResolvers, buildSchema } from './../src/index' +import { createYoga } from 'graphql-yoga' +import { createServer } from 'http' + +const node = { + id: g.id() +} + +const name = { + name: g.string() +} + +const test = g.type('Test', {}).extend([node, name]) + +const queryType = g.type('Query', { + test: g.ref(() => test) +}) + +type Test = Infer + +const resolvers: InferResolvers<{ Query: typeof queryType, Test: typeof test }, {}> = { + Query: { + test: (parent, args, context, info) => { + return { + id: '123', + name: 'Test' + } + } + }, + Test: { + id: (parent, args, context, info) => { + return parent.id + }, + name: (parent, args, context, info) => { + return parent.name + } + } +} + +const schema = buildSchema({ g, resolvers }) +const yoga = createYoga({ schema }) +const server = createServer(yoga) +server.listen(4000, () => { + console.info('Server is running on http://localhost:4000/graphql') +}) diff --git a/package-lock.json b/package-lock.json index 92d6cba..41b0788 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "garph", - "version": "0.6.2", + "version": "0.6.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "garph", - "version": "0.6.2", + "version": "0.6.3", "license": "MIT", "dependencies": { "graphql-compose": "^9.0.10", diff --git a/package.json b/package.json index 35ca26e..227227d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/stepci/garph" }, - "version": "0.6.2", + "version": "0.6.3", "license": "MIT", "main": "dist/index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index b7ac9c9..fc6741c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,7 +36,8 @@ export type TypeDefinition = { deprecated?: string scalarOptions?: ScalarOptions defaultValue?: any - interfaces?: AnyType[] + interfaces?: AnyInterface[] + extend?: AnyTypes[] } export type AnyType = Type @@ -177,53 +178,74 @@ export type InferResolversStrict extends Type { declare _name: N - constructor(name: string, shape: T, interfaces?: AnyInterface[]) { + constructor(name: string, shape: T, interfaces?: AnyInterface[], extend?: AnyTypes[]) { super() this.typeDef = { name, type: 'ObjectType', shape, - interfaces + interfaces, + extend } } implements(ref: D | D[]) { // This is temporary construct, until we figure out how to properly manage to shared schema this.typeDef.interfaces = Array.isArray(ref) ? ref : [ref] - return new GType>(this.typeDef.name, this.typeDef.shape as any, Array.isArray(ref) ? ref : [ref]) + return new GType>(this.typeDef.name, this.typeDef.shape as any, Array.isArray(ref) ? ref : [ref], this.typeDef.extend) + } + + extend(ref: D | D[]) { + // This is temporary construct, until we figure out how to properly manage to shared schema + this.typeDef.extend = Array.isArray(ref) ? ref : [ref] + return new GType>(this.typeDef.name, this.typeDef.shape as any, this.typeDef.interfaces, Array.isArray(ref) ? ref : [ref]) } } class GInput extends Type { declare _name: N - constructor(name: string, shape: T) { + constructor(name: string, shape: T, extend?: AnyTypes[]) { super() this.typeDef = { name, type: 'InputType', - shape + shape, + extend } } + + extend(ref: D | D[]) { + // This is temporary construct, until we figure out how to properly manage to shared schema + this.typeDef.extend = Array.isArray(ref) ? ref : [ref] + return new GInput>(this.typeDef.name, this.typeDef.shape as any, Array.isArray(ref) ? ref : [ref]) + } } class GInterface extends Type { declare _name: N - constructor(name: string, shape: T, interfaces?: AnyInterface[]) { + constructor(name: string, shape: T, interfaces?: AnyInterface[], extend?: AnyTypes[]) { super() this.typeDef = { name, type: 'InterfaceType', shape, - interfaces + interfaces, + extend } } implements(ref: D | D[]) { // This is temporary construct, until we figure out how to properly manage to shared schema this.typeDef.interfaces = Array.isArray(ref) ? ref : [ref] - return new GInterface>(this.typeDef.name, this.typeDef.shape as any, Array.isArray(ref) ? ref : [ref]) + return new GInterface>(this.typeDef.name, this.typeDef.shape as any, Array.isArray(ref) ? ref : [ref], this.typeDef.extend) + } + + extend(ref: D | D[]) { + // This is temporary construct, until we figure out how to properly manage to shared schema + this.typeDef.extend = Array.isArray(ref) ? ref : [ref] + return new GInterface>(this.typeDef.name, this.typeDef.shape as any, this.typeDef.interfaces, Array.isArray(ref) ? ref : [ref]) } } diff --git a/src/schema.ts b/src/schema.ts index ca043a9..10d0908 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -98,6 +98,12 @@ export function convertToGraphqlType(schemaComposer: SchemaComposer, name: strin }) } + if (type.typeDef.extend) { + type.typeDef.extend.forEach(i => { + objType.addFields(parseFields(schemaComposer, name, i as any, config, resolvers)) + }) + } + return objType case 'Enum': return schemaComposer.createEnumTC({ @@ -116,11 +122,19 @@ export function convertToGraphqlType(schemaComposer: SchemaComposer, name: strin resolveType: resolvers?.resolveType }) case 'InputType': - return schemaComposer.createInputTC({ + const inputType = schemaComposer.createInputTC({ name, description: type.typeDef.description, fields: parseFields(schemaComposer, name, type.typeDef.shape, config), }) + + if (type.typeDef.extend) { + type.typeDef.extend.forEach(i => { + inputType.addFields(parseFields(schemaComposer, name, i as any, config, resolvers)) + }) + } + + return inputType case 'Scalar': return schemaComposer.createScalarTC({ name, @@ -145,6 +159,12 @@ export function convertToGraphqlType(schemaComposer: SchemaComposer, name: strin }) } + if (type.typeDef.extend) { + type.typeDef.extend.forEach(i => { + interfaceType.addFields(parseFields(schemaComposer, name, i as any, config, resolvers)) + }) + } + return interfaceType } } diff --git a/www/api/classes/GarphSchema.md b/www/api/classes/GarphSchema.md index 7aa518a..508a1b2 100644 --- a/www/api/classes/GarphSchema.md +++ b/www/api/classes/GarphSchema.md @@ -17,7 +17,7 @@ #### Defined in -[index.ts:596](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L596) +[index.ts:618](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L618) ## Properties @@ -27,7 +27,7 @@ #### Defined in -[index.ts:578](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L578) +[index.ts:600](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L600) ___ @@ -46,7 +46,7 @@ ___ #### Defined in -[index.ts:589](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L589) +[index.ts:611](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L611) ___ @@ -56,7 +56,7 @@ ___ #### Defined in -[index.ts:582](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L582) +[index.ts:604](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L604) ___ @@ -66,7 +66,7 @@ ___ #### Defined in -[index.ts:577](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L577) +[index.ts:599](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L599) ## Methods @@ -80,7 +80,7 @@ ___ #### Defined in -[index.ts:681](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L681) +[index.ts:703](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L703) ___ @@ -108,7 +108,7 @@ ___ #### Defined in -[index.ts:612](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L612) +[index.ts:634](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L634) ___ @@ -136,7 +136,7 @@ ___ #### Defined in -[index.ts:622](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L622) +[index.ts:644](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L644) ___ @@ -164,7 +164,7 @@ ___ #### Defined in -[index.ts:641](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L641) +[index.ts:663](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L663) ___ @@ -178,7 +178,7 @@ ___ #### Defined in -[index.ts:677](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L677) +[index.ts:699](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L699) ___ @@ -192,7 +192,7 @@ ___ #### Defined in -[index.ts:669](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L669) +[index.ts:691](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L691) ___ @@ -220,7 +220,7 @@ ___ #### Defined in -[index.ts:635](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L635) +[index.ts:657](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L657) ___ @@ -234,7 +234,7 @@ ___ #### Defined in -[index.ts:673](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L673) +[index.ts:695](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L695) ___ @@ -262,7 +262,7 @@ ___ #### Defined in -[index.ts:659](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L659) +[index.ts:681](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L681) ___ @@ -290,7 +290,7 @@ ___ #### Defined in -[index.ts:606](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L606) +[index.ts:628](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L628) ___ @@ -316,7 +316,7 @@ ___ #### Defined in -[index.ts:687](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L687) +[index.ts:709](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L709) ___ @@ -344,7 +344,7 @@ ___ #### Defined in -[index.ts:653](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L653) +[index.ts:675](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L675) ___ @@ -358,7 +358,7 @@ ___ #### Defined in -[index.ts:665](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L665) +[index.ts:687](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L687) ___ @@ -386,7 +386,7 @@ ___ #### Defined in -[index.ts:600](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L600) +[index.ts:622](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L622) ___ @@ -414,4 +414,4 @@ ___ #### Defined in -[index.ts:647](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L647) +[index.ts:669](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L669) diff --git a/www/api/classes/Type.md b/www/api/classes/Type.md index 87385ad..45d3289 100644 --- a/www/api/classes/Type.md +++ b/www/api/classes/Type.md @@ -30,7 +30,7 @@ #### Defined in -[index.ts:13](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L13) +[index.ts:13](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L13) ___ @@ -40,7 +40,7 @@ ___ #### Defined in -[index.ts:11](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L11) +[index.ts:11](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L11) ___ @@ -50,7 +50,7 @@ ___ #### Defined in -[index.ts:10](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L10) +[index.ts:10](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L10) ___ @@ -60,7 +60,7 @@ ___ #### Defined in -[index.ts:9](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L9) +[index.ts:9](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L9) ___ @@ -70,7 +70,7 @@ ___ #### Defined in -[index.ts:12](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L12) +[index.ts:12](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L12) ___ @@ -80,7 +80,7 @@ ___ #### Defined in -[index.ts:14](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L14) +[index.ts:14](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L14) ___ @@ -90,7 +90,7 @@ ___ #### Defined in -[index.ts:15](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L15) +[index.ts:15](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L15) ## Methods @@ -110,7 +110,7 @@ ___ #### Defined in -[index.ts:22](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L22) +[index.ts:22](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L22) ___ @@ -130,4 +130,4 @@ ___ #### Defined in -[index.ts:17](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L17) +[index.ts:17](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L17) diff --git a/www/api/index.md b/www/api/index.md index 870e1b6..44375c2 100644 --- a/www/api/index.md +++ b/www/api/index.md @@ -15,7 +15,7 @@ garph #### Defined in -[index.ts:57](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L57) +[index.ts:58](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L58) ___ @@ -25,7 +25,7 @@ ___ #### Defined in -[index.ts:45](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L45) +[index.ts:46](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L46) ___ @@ -35,7 +35,7 @@ ___ #### Defined in -[index.ts:53](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L53) +[index.ts:54](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L54) ___ @@ -45,7 +45,7 @@ ___ #### Defined in -[index.ts:48](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L48) +[index.ts:49](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L49) ___ @@ -55,7 +55,7 @@ ___ #### Defined in -[index.ts:44](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L44) +[index.ts:45](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L45) ___ @@ -65,7 +65,7 @@ ___ #### Defined in -[index.ts:55](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L55) +[index.ts:56](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L56) ___ @@ -75,7 +75,7 @@ ___ #### Defined in -[index.ts:47](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L47) +[index.ts:48](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L48) ___ @@ -85,7 +85,7 @@ ___ #### Defined in -[index.ts:56](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L56) +[index.ts:57](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L57) ___ @@ -95,7 +95,7 @@ ___ #### Defined in -[index.ts:50](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L50) +[index.ts:51](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L51) ___ @@ -105,7 +105,7 @@ ___ #### Defined in -[index.ts:46](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L46) +[index.ts:47](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L47) ___ @@ -115,7 +115,7 @@ ___ #### Defined in -[index.ts:59](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L59) +[index.ts:60](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L60) ___ @@ -129,7 +129,7 @@ ___ #### Defined in -[index.ts:70](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L70) +[index.ts:71](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L71) ___ @@ -139,7 +139,7 @@ ___ #### Defined in -[index.ts:60](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L60) +[index.ts:61](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L61) ___ @@ -149,7 +149,7 @@ ___ #### Defined in -[index.ts:58](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L58) +[index.ts:59](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L59) ___ @@ -159,7 +159,7 @@ ___ #### Defined in -[index.ts:51](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L51) +[index.ts:52](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L52) ___ @@ -169,7 +169,7 @@ ___ #### Defined in -[index.ts:49](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L49) +[index.ts:50](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L50) ___ @@ -179,7 +179,7 @@ ___ #### Defined in -[index.ts:54](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L54) +[index.ts:55](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L55) ___ @@ -189,7 +189,7 @@ ___ #### Defined in -[index.ts:43](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L43) +[index.ts:44](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L44) ___ @@ -199,7 +199,7 @@ ___ #### Defined in -[index.ts:42](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L42) +[index.ts:43](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L43) ___ @@ -213,7 +213,7 @@ ___ #### Defined in -[index.ts:66](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L66) +[index.ts:67](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L67) ___ @@ -223,7 +223,7 @@ ___ #### Defined in -[index.ts:52](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L52) +[index.ts:53](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L53) ___ @@ -237,7 +237,7 @@ ___ #### Defined in -[index.ts:62](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L62) +[index.ts:63](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L63) ___ @@ -254,7 +254,7 @@ ___ #### Defined in -[index.ts:92](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L92) +[index.ts:93](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L93) ___ @@ -270,7 +270,7 @@ ___ #### Defined in -[index.ts:124](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L124) +[index.ts:125](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L125) ___ @@ -286,7 +286,7 @@ ___ #### Defined in -[index.ts:125](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L125) +[index.ts:126](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L126) ___ @@ -302,7 +302,7 @@ ___ #### Defined in -[index.ts:119](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L119) +[index.ts:120](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L120) ___ @@ -318,7 +318,7 @@ ___ #### Defined in -[index.ts:120](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L120) +[index.ts:121](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L121) ___ @@ -335,7 +335,7 @@ ___ #### Defined in -[index.ts:93](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L93) +[index.ts:94](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L94) ___ @@ -352,7 +352,7 @@ ___ #### Defined in -[index.ts:133](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L133) +[index.ts:134](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L134) ___ @@ -369,7 +369,7 @@ ___ #### Defined in -[index.ts:155](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L155) +[index.ts:156](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L156) ___ @@ -386,7 +386,7 @@ ___ #### Defined in -[index.ts:107](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L107) +[index.ts:108](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L108) ___ @@ -402,7 +402,7 @@ ___ #### Defined in -[index.ts:131](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L131) +[index.ts:132](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L132) ___ @@ -424,7 +424,8 @@ ___ | `defaultValue?` | `any` | | `deprecated?` | `string` | | `description?` | `string` | -| `interfaces?` | [`AnyType`](index.md#anytype)[] | +| `extend?` | [`AnyTypes`](index.md#anytypes)[] | +| `interfaces?` | [`AnyInterface`](index.md#anyinterface)[] | | `isOptional?` | `boolean` | | `isRequired?` | `boolean` | | `name?` | `string` | @@ -434,7 +435,7 @@ ___ #### Defined in -[index.ts:28](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L28) +[index.ts:28](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L28) ## Variables @@ -444,7 +445,7 @@ ___ #### Defined in -[index.ts:700](https://github.com/stepci/garph/blob/f2d3630/src/index.ts#L700) +[index.ts:722](https://github.com/stepci/garph/blob/3fdff10/src/index.ts#L722) ## Functions @@ -467,7 +468,7 @@ ___ #### Defined in -[schema.ts:17](https://github.com/stepci/garph/blob/f2d3630/src/schema.ts#L17) +[schema.ts:17](https://github.com/stepci/garph/blob/3fdff10/src/schema.ts#L17) ___ @@ -488,4 +489,4 @@ ___ #### Defined in -[schema.ts:11](https://github.com/stepci/garph/blob/f2d3630/src/schema.ts#L11) +[schema.ts:11](https://github.com/stepci/garph/blob/3fdff10/src/schema.ts#L11) diff --git a/www/docs/guide/schemas.md b/www/docs/guide/schemas.md index 4fc29aa..6d694e2 100644 --- a/www/docs/guide/schemas.md +++ b/www/docs/guide/schemas.md @@ -375,6 +375,32 @@ type Test implements interface { } ``` +### Extend + +Define a set of properties that extends an input, interface or object type + +```ts +const name = { + name: g.string() +} + +const test = g.type('Test', {}).extend(name) +``` + +Or array of properties: + +```ts +const test = g.type('Test', {}).extend([firstname, lastname]) +``` + +GraphQL Type: + +```graphql +extend type Test { + name: String! +} +``` + ### List Turns a particular type into a list