简体   繁体   中英

GraphQL & Prisma: why does one redefine types in the application schema when they are already part of the Prisma database schema?

Hi — I've been following along with a GraphQL/Prisma tutorial ( https://www.howtographql.com/graphql-js/6-authentication/ ) and I'm wondering why one redefines types in the application schema when they are already part of the Prisma database schema and could be imported from there.

The answer the tutorial gives is “To hide potentially sensitive information from client applications”. What does this mean exactly? Why do we replicate definitions in 'schema.graphql' and 'datamodel.prisma'? Because the definitions are slightly different (ie the 'datamodel' contains tags like @unique )? And how are we hiding things from client applications? I remain perplexed....

Specifically in 'schema.graphql' I have

type User {
    id: ID!
    name: String!
    email: String!
    links: [Link!]!
}

and in 'datamodel.prisma' I have

type User {
    id: ID! @unique
    name: String!
    email: String! @unique
    password: String!
    links: [ Link!] !
}

The schema doesn't have the password field, that is likely what is meant by " hide potentially sensitive information ".

This is common practice in any API to not return all data from the persistent storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM