This repository contains the code for the GraphQL subscriptions tutorial on the Graphcool blog.
Clone the repository:
git clone [email protected]:nikolasburk/subscriptions.git
Next, navigate into the downloaded folder and install the NPM dependencies:
cd subscriptions
yarn install
You can now deploy the Prisma database API:
yarn prisma deploy
When prompted by the CLI how you want to deploy your Prisma API, select either of the Prisma Sandbox options: sandbox-eu1
or sandbox-us1
. Then provide a name for your API and the stage or simply hit Enter to select the suggested values.
Note:
prisma
is listed as a development dependency and script in this project'spackage.json
. This means you can invoke the Prisma CLI without having it globally installed on your machine (by prefixing it withyarn
), e.g.yarn prisma deploy
oryarn prisma playground
. If you have the Prisma CLI installed globally (which you can do withnpm install -g prisma
), you can omit theyarn
prefix.
From the output of the previous command, copy the HTTP
endpoint and paste it into src/index.js
where it's used to instantiate the Prisma
binding. You need to replace the current placeholder __PRISMA_ENDPOINT__
:
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: "__PRISMA_ENDPOINT__",
secret: 'mysecret123',
}),
}),
})
For example:
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: "https://eu1.prisma.sh/public-hillcloak-flier-942261/hackernews-graphql-js/dev",
secret: 'mysecret123',
}),
}),
})
Note that the part public-hillcloak-flier-952361
of the URL is unique to your service.
You can now test the API with the following command:
yarn dev
The server is now running on http://localhost:4000 and a GraphQL Playground opens automatically so you can start sending requests to your GraphQL API.
To learn more about this example, check out the corresponding tutorial.