Unverified Commit f9cb5ac6 authored by Flavian Desverne's avatar Flavian Desverne Committed by GitHub

Replace Graphcool with dedicated example GraphQL server using Prisma (#15752)

## Motivation

As Graphcool is being shutdown, we replaced all the graphcool api endpoints with some handcrafted APIs using Prisma & Nexus, that can be found here https://github.com/prisma-labs/nextjs-graphql-api-examples. These GraphQL endpoints are now deployed to Vercel.

## Notes

- I couldn't get the reason-relay example to run. Given that the relay endpoint works on the other relay example, I don't see any reason why it wouldn't work on that one
- The `with-apollo` example is buggy when creating some posts, but nothing related to the switch of the api endpoint as it was already buggy before. I suspect the `concatPagination` strategy to be the cause of that bug, but I couldn't figure it out.

Fixes #14780
parent 5db2860c
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
In this simple example, we integrate Apollo seamlessly with [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching) to fetch queries in the server and hydrate them in the browser. In this simple example, we integrate Apollo seamlessly with [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching) to fetch queries in the server and hydrate them in the browser.
This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend. This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.
## Demo ## Demo
......
...@@ -4,7 +4,7 @@ import PostUpvoter from './PostUpvoter' ...@@ -4,7 +4,7 @@ import PostUpvoter from './PostUpvoter'
export const ALL_POSTS_QUERY = gql` export const ALL_POSTS_QUERY = gql`
query allPosts($first: Int!, $skip: Int!) { query allPosts($first: Int!, $skip: Int!) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) { allPosts(orderBy: { createdAt: desc }, first: $first, skip: $skip) {
id id
title title
votes votes
......
import { gql, useMutation } from '@apollo/client' import { gql, useMutation } from '@apollo/client'
const UPDATE_POST_MUTATION = gql` const UPDATE_POST_MUTATION = gql`
mutation updatePost($id: ID!, $votes: Int) { mutation votePost($id: String!) {
updatePost(id: $id, votes: $votes) { votePost(id: $id) {
__typename
id id
votes votes
__typename
} }
} }
` `
...@@ -17,11 +17,10 @@ export default function PostUpvoter({ votes, id }) { ...@@ -17,11 +17,10 @@ export default function PostUpvoter({ votes, id }) {
updatePost({ updatePost({
variables: { variables: {
id, id,
votes: votes + 1,
}, },
optimisticResponse: { optimisticResponse: {
__typename: 'Mutation', __typename: 'Mutation',
updatePost: { votePost: {
__typename: 'Post', __typename: 'Post',
id, id,
votes: votes + 1, votes: votes + 1,
......
...@@ -31,7 +31,7 @@ export default function Submit() { ...@@ -31,7 +31,7 @@ export default function Submit() {
query: ALL_POSTS_QUERY, query: ALL_POSTS_QUERY,
variables: allPostsQueryVars, variables: allPostsQueryVars,
}) })
// Update the cache with the new post at the top of the // Update the cache with the new post at the top of the list
proxy.writeQuery({ proxy.writeQuery({
query: ALL_POSTS_QUERY, query: ALL_POSTS_QUERY,
data: { data: {
......
...@@ -8,7 +8,7 @@ function createApolloClient() { ...@@ -8,7 +8,7 @@ function createApolloClient() {
return new ApolloClient({ return new ApolloClient({
ssrMode: typeof window === 'undefined', ssrMode: typeof window === 'undefined',
link: new HttpLink({ link: new HttpLink({
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute) uri: 'https://nextjs-graphql-with-prisma-simple.vercel.app/api', // Server URL (must be absolute)
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers` credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
}), }),
cache: new InMemoryCache({ cache: new InMemoryCache({
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@apollo/client": "^3.0.0", "@apollo/client": "3.1.1",
"graphql": "^15.3.0", "graphql": "^15.3.0",
"next": "latest", "next": "latest",
"prop-types": "^15.6.2", "prop-types": "^15.6.2",
......
NEXT_PUBLIC_RELAY_ENDPOINT=https://api.graph.cool/relay/v1/next-js-with-relay-modern-example NEXT_PUBLIC_RELAY_ENDPOINT=https://nextjs-graphql-with-prisma-relay.vercel.app/api
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"schemaPath": "schema/schema.graphql", "schemaPath": "schema/schema.graphql",
"extensions": { "extensions": {
"endpoints": { "endpoints": {
"dev": "https://api.graph.cool/relay/v1/next-js-with-relay-modern-example" "dev": "https://nextjs-graphql-with-prisma-relay.vercel.app/api"
} }
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
[Relay Modern](https://relay.dev/) is a new version of Relay designed from the ground up to be easier to use, more extensible and, most of all, able to improve performance on mobile devices. Relay Modern accomplishes this with static queries and ahead-of-time code generation. [Relay Modern](https://relay.dev/) is a new version of Relay designed from the ground up to be easier to use, more extensible and, most of all, able to improve performance on mobile devices. Relay Modern accomplishes this with static queries and ahead-of-time code generation.
This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend. This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.
## Deploy your own ## Deploy your own
......
...@@ -13,7 +13,7 @@ const BlogPosts = ({ viewer }) => ( ...@@ -13,7 +13,7 @@ const BlogPosts = ({ viewer }) => (
export default createFragmentContainer(BlogPosts, { export default createFragmentContainer(BlogPosts, {
viewer: graphql` viewer: graphql`
fragment BlogPosts_viewer on Viewer { fragment BlogPosts_viewer on Viewer {
allBlogPosts(first: 10, orderBy: createdAt_DESC) { allBlogPosts(first: 10, orderBy: { createdAt: desc }) {
edges { edges {
node { node {
...BlogPostPreview_post ...BlogPostPreview_post
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"version": "3.0.3", "version": "3.0.3",
"description": "Example of Next.js with Relay Modern and react-relay-network-modern", "description": "Example of Next.js with Relay Modern and react-relay-network-modern",
"scripts": { "scripts": {
"graphcool-init": "graphcool init --schema schema/init-schema.graphql",
"dev": "next", "dev": "next",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
...@@ -23,7 +22,6 @@ ...@@ -23,7 +22,6 @@
}, },
"devDependencies": { "devDependencies": {
"babel-plugin-relay": "^9.0.0", "babel-plugin-relay": "^9.0.0",
"graphcool": "^1.2.1",
"graphql-cli": "^3.0.11", "graphql-cli": "^3.0.11",
"relay-compiler": "^9.0.0" "relay-compiler": "^9.0.0"
} }
......
type BlogPost implements Node {
content: String!
createdAt: DateTime!
id: ID! @isUnique
title: String!
updatedAt: DateTime!
}
RELAY_ENDPOINT=https://api.graph.cool/relay/v1/next-js-with-relay-modern-example RELAY_ENDPOINT=https://nextjs-graphql-with-prisma-relay.vercel.app/api
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"schemaPath": "schema/schema.graphql", "schemaPath": "schema/schema.graphql",
"extensions": { "extensions": {
"endpoints": { "endpoints": {
"dev": "https://api.graph.cool/relay/v1/next-js-with-relay-modern-example" "dev": "https://nextjs-graphql-with-prisma-relay.vercel.app/api"
} }
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
[Reason Relay](https://reason-relay-documentation.zth.now.sh/) [Reason Relay](https://reason-relay-documentation.zth.now.sh/)
This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend. This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.
## Deploy your own ## Deploy your own
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"version": "3.0.4", "version": "3.0.4",
"description": "Example of Next.js with Relay Modern SSR", "description": "Example of Next.js with Relay Modern SSR",
"scripts": { "scripts": {
"graphcool-init": "graphcool init --schema schema/init-schema.graphql",
"dev": "next", "dev": "next",
"build": "bsb -make-world", "build": "bsb -make-world",
"next": "next", "next": "next",
...@@ -34,7 +33,6 @@ ...@@ -34,7 +33,6 @@
}, },
"devDependencies": { "devDependencies": {
"babel-plugin-relay": "^9.0.0", "babel-plugin-relay": "^9.0.0",
"graphcool": "^1.4.0",
"graphql-cli": "^3.0.14", "graphql-cli": "^3.0.14",
"relay-compiler": "9.0.0" "relay-compiler": "9.0.0"
}, },
......
type BlogPost implements Node {
content: String!
createdAt: DateTime!
id: ID! @isUnique
title: String!
updatedAt: DateTime!
}
module Fragment = [%relay.fragment {| module Fragment = [%relay.fragment {|
fragment BlogPosts_fragment on Viewer { fragment BlogPosts_fragment on Viewer {
allBlogPosts(first: 10, orderBy: createdAt_DESC) { allBlogPosts(first: 10, orderBy: { createdAt: desc }) {
edges { edges {
node { node {
...BlogPostPreview_fragment ...BlogPostPreview_fragment
......
NEXT_PUBLIC_RELAY_ENDPOINT=https://api.graph.cool/relay/v1/next-js-with-relay-modern-example NEXT_PUBLIC_RELAY_ENDPOINT=https://nextjs-graphql-with-prisma-relay.vercel.app/api
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"schemaPath": "schema/schema.graphql", "schemaPath": "schema/schema.graphql",
"extensions": { "extensions": {
"endpoints": { "endpoints": {
"dev": "https://api.graph.cool/relay/v1/next-js-with-relay-modern-example" "dev": "https://nextjs-graphql-with-prisma-relay.vercel.app/api"
} }
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
[Relay Modern](https://relay.dev/) is a new version of Relay designed from the ground up to be easier to use, more extensible and, most of all, able to improve performance on mobile devices. Relay Modern accomplishes this with static queries and ahead-of-time code generation. [Relay Modern](https://relay.dev/) is a new version of Relay designed from the ground up to be easier to use, more extensible and, most of all, able to improve performance on mobile devices. Relay Modern accomplishes this with static queries and ahead-of-time code generation.
This example relies on [graph.cool](https://www.graph.cool) for its GraphQL backend. This example relies on [Prisma + Nexus](https://github.com/prisma-labs/nextjs-graphql-api-examples) for its GraphQL backend.
## Deploy your own ## Deploy your own
......
...@@ -15,7 +15,7 @@ const BlogPosts = ({ viewer }) => ( ...@@ -15,7 +15,7 @@ const BlogPosts = ({ viewer }) => (
export default createFragmentContainer(BlogPosts, { export default createFragmentContainer(BlogPosts, {
viewer: graphql` viewer: graphql`
fragment BlogPosts_viewer on Viewer { fragment BlogPosts_viewer on Viewer {
allBlogPosts(first: 10, orderBy: createdAt_DESC) { allBlogPosts(first: 10, orderBy: { createdAt: desc }) {
edges { edges {
node { node {
...BlogPostPreview_post ...BlogPostPreview_post
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"version": "1.0.0", "version": "1.0.0",
"description": "Example of Next.js with Relay Modern", "description": "Example of Next.js with Relay Modern",
"scripts": { "scripts": {
"graphcool-init": "graphcool init --schema schema/init-schema.graphql",
"dev": "next", "dev": "next",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
...@@ -20,7 +19,6 @@ ...@@ -20,7 +19,6 @@
}, },
"devDependencies": { "devDependencies": {
"babel-plugin-relay": "^9.0.0", "babel-plugin-relay": "^9.0.0",
"graphcool": "^1.4.0",
"graphql-cli": "^3.0.14", "graphql-cli": "^3.0.14",
"relay-compiler": "^9.0.0" "relay-compiler": "^9.0.0"
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment