yarn install
yarn seed && yarn dev
open http://localhost:3000
User: simple schema with one type
This example has simple User mongoose model that supports bunch of CRUD operations.
constUserSchema=newmongoose.Schema({name: String,// standard typesage: {type: Number,index: true,},languages: {type: [LanguagesSchema],// you may include other schemas (here included as array of embedded documents)default: [],},contacts: {// another mongoose way for providing embedded documentsemail: String,phones: [String],// array of strings},gender: {// enum field with valuestype: String,enum: ['male','female','ladyboy'],},});
User for Relay: simple schema with one type
This schema shows all available CRUD operations which are compatible with Relay. It uses graphql-compose-mongose and graphql-compose-relay:
composeWithRelay(RootQueryTC) adds node field to the RootQuery. Via RootQuery.node(id) you may find objects by globally unique ID among all types.
composeWithRelay(UserTC) - modify UserTC generated by graphql-compose-mongoose
adds id field with Relay's globally unique ID
this type will be added to NodeInterface for resolving via RootQuery.node
for mutations will be added clientMutationId to input and output objects types
also all arguments in mutations will be moved into input arg
请发表评论