Skip to content

Instantly share code, notes, and snippets.

View nikolasburk's full-sized avatar
😑

Nikolas nikolasburk

😑
View GitHub Profile

Data model vs Prisma database schema

When starting out with GraphQL and Prisma, the amount of .graphql-files you're working with can be confusing. Yet, it's crucial to understand what the role of each of them is.

Looking only at Prisma, there are two .graphql-files that are relevant:

  • The data model containing the model definitions for your service's APIs, typically called datamodel.graphql.
  • The Prisma database schema defining the actual CRUD/realtime operations of the service's API, typically called prisma.graphql.
// graphql-yoga
const server = new GraphQLServer({ schema })
server.start(() => {
console.log(`Server ready at http://localhost:4000`)
})
// apollo-server
const server = new ApolloServer({ schema })
server.listen({ port: 4000 }, () =>
console.log(`Server ready at http://localhost:4000`),
)
// express-graphql
const app = express()
app.use('/graphql', graphqlHTTP({ schema }))
app.listen(4000, () => {
console.log(`Server ready at http://localhost:4000`)
})
type User {
id: ID!
name: String
}
type Query {
user(id: ID!): User
}
const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
},
})
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
import { DMMF, DMMFClass, Engine } from './runtime';
/**
* Utility Types
*/
export declare type Enumerable<T> = T | Array<T>;
export declare type MergeTruthyValues<R extends object, S extends object> = {
[key in keyof S | keyof R]: key extends false ? never : key extends keyof S ? S[key] extends false ? never : S[key] : key extends keyof R ? R[key] : never;
};
export declare type CleanupNever<T> = {
[key in keyof T]: T[key] extends never ? never : key;

Test

Challenge 1

Setup instructions:

git clone https://github.com/prisma/support-challenges
cd support-challenges/challenge-1
# Create local Postgres DB called "test1"

I'm using these prisma2 versions:

{
  "dependencies": {
    "@prisma/photon": "alpha"
  },
  "devDependencies": {
    "prisma2": "alpha",
    "ts-node-dev": "^1.0.0-pre.44",
datasource sqlite {
url = "file:data.db"
provider = "sqlite"
}
generator photonjs {
provider = "photonjs"
}
model User {