[ ] GraphQL . |
user
, : firstName
lastName
.query myQuery{
user {
firstName
lastName
}
}
query
. , , , . mutation myMutation{
UserCreate(data: {firstName: "Jane", lastName: "Dohe"})
}
Queries , mutations .
subscriptions mySubscription{
user {
firstName
lastName
}
}
query myQuery($id: '1'){
user (id:$id){
firstName
lastName
}
}
id = '1'
firstName
lastName
.query myQuery($id: ID){ //
user (id:$id){
firstName
lastName
}
}
{
"id": "595fdbe2cc86ed070ce1da52" //
}
ID!
GraphQL, .// 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
. GraphQLBolean , :mutation auth($email: String!, $password: String!) {
auth(email: $email, password: $password) {
id
secure {
public_key
}
}
}