Understanding GraphQL schemas
As stated, GraphQL is a language used to provide structure and type information to our entity data. Regardless of which vendor's implementation of GraphQL is used on the server, our client can expect the same data structures to be returned. This ability to abstract away the implementation details of servers to clients is one of the strengths of GraphQL.
Let's create a simple GraphQL schema and see what it looks like:
- In the
Chap9
folder, create a new folder calledgraphql-schema
. - Open your terminal in that folder and then run this command, accepting the defaults:
npm init
- Now install these packages:
npm i express apollo-server-express @types/express
- Initialize TypeScript with this command:
tsc -init
Notice, after this command completes, that the default
tsconfig.json
setting is strict. - Create a new TypeScript file called
typeDefs.ts
and add this to it:import { gql } from "apollo-server-express";
This import gets...