user
field and tell what values the server should return: firstName
and lastName
. query myQuery{ user { firstName lastName } }
query
before curly braces. However, when writing requests on the client, if you do NOT explicitly specify the type of request, there will be an error. mutation myMutation{ UserCreate(firstName: "Jane", lastName: "Dohe") }
Queries are asynchronous, and mutations are sequential.
subscriptions mySubscription{ user { firstName lastName } }
query myQuery($id: '1'){ user (id:$id){ firstName lastName } }
id = '1'
and return us his firstName
and lastName
. query myQuery($id: ID){ // user (id:$id){ firstName lastName } }
{ "id": "595fdbe2cc86ed070ce1da52" // }
ID!
- The exclamation point at the end of the type tells GraphQL that this field is required. // MongoDB schema const schema = new mongoose.Schema({ firstName: { type: String }, lastName: { type: String }, }) export const USER_MODEL = mongoose.model('users', schema) // GraphQL type const user = { firstName: { type: GraphQLString }, lastName: { type: GraphQLString }, } export const USER = new GraphQLObjectType({ name: 'USER', fields: user })
// MongoDB schema const schema = new mongoose.Schema({ firstName: { type: String }, lastName: { type: String }, secure: { public_key: { type: String }, private_key: { type: String }, }, }) . . . const secure = new GraphQLObjectType({ name: "public_key", fields: { public_key: { type: GraphQLString } } }) export const USER = new GraphQLObjectType({ name: "USER", fields: { firstName: { type: GraphQLID }, secure: { type: secure } } })
query myQuery($id: ID){ user (id:$id){ firstName secure { public_key } } }
true/false
Boolean values. If the server in the field type instead of GraphQLBolean specify the type of the model, then you get the following: mutation auth($email: String!, $password: String!) { auth(email: $email, password: $password) { id secure { public_key } } }
Source: https://habr.com/ru/post/332850/
All Articles