How does GraphQL Mutation associate itself with Type


#1

When I set up my schema as following:

type Mutation {
    createUser(data: CreateUserInput!): User!
}

type User {
    id: ID!
    name: String!
    password: String!
    email: String!
    posts: [Post!]!
    comments: [Comment!]!
}

and my resolver:

const Mutation = {
    async createUser(parent, args, { prisma }, info) {
        if(args.data.password.length < 8) {
            throw new Error("Pasword must be 8 characters or longer")
        }
        return prisma.mutation.createUser({ 
            data: {
                ...args.data,
                password
            } 
        })
    }
}

how does GraphQL know that createUser is associated with my User model? I could set it up so that createUser returns token instead of User (after generating a token) or I could rename createUser to createPerson . I have never defined the association between createUser and User . I’m unsure how my data input through createUser gets directed to be saved in the user table, instead of another table.


#2

Hi @kevv,

Whenever you run prisma deploy command, create a bunch of operation using your datamodel. We reference the typename and other metadata.

You can use the prisma playground command and explore the schema yourself. We use GraphQL as a wire protocol between your application server and prisma server.