Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
mid

Static type checking between resolvers and typedef

// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
// your data.
import gql from 'graphql-tag'
export const typeDefs = gql`
  # Comments in GraphQL strings (such as this one) start with the hash (#) symbol.

  # This "Book" type defines the queryable fields for every book in our data source.
  type Book {
    title: String
    author: String
  }

  # The "Query" type is special: it lists all of the available queries that
  # clients can execute, along with the return type for each. In this
  # case, the "books" query returns an array of zero or more Books (defined above).
  type Query {
    books: [Book]
  }
`;

Resolver
import { books } from "./types/books";
import { prisma } from "../db/client";

export const resolvers = {
  Query: {
    books: async () => {
      return await prisma.book.findMany();
    },
  },
};
Was this page helpful?