Skip to content

Commit 0adffc2

Browse files
authored
simplify Next.js example + add symlinks to React Vite to maintain 2 examples from 1 place (#3281)
1 parent e54f7d9 commit 0adffc2

33 files changed

+780
-622
lines changed

.eslintrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
module.exports = {
1111
root: true,
1212
reportUnusedDisableDirectives: true,
13-
ignorePatterns: [
14-
// CRA example has its own eslint config
15-
'examples/graphiql-create-react-app',
16-
],
13+
ignorePatterns: ['react-app-env.d.ts', 'next-env.d.ts'],
1714
overrides: [
1815
{
1916
// Rules for all code files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## GraphiQL `create-react-app` Example
1+
# GraphiQL `create-react-app` Example
22

33
This example demonstrates how to transpile your own custom ES6 and typescript GraphiQL implementation bootstrapped with `create-react-app`, no config needed.
44

5-
### Setup
5+
## Setup
66

77
1. `yarn` and `yarn start` from this folder to start `react-scripts` dev server.
88
1. `yarn build` from this folder to build production ready transpiled files using `react-scripts`. Find the output in `build` folder.

examples/graphiql-create-react-app/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"start": "react-scripts start",
1414
"build": "react-scripts build"
1515
},
16-
"eslintConfig": {
17-
"extends": "react-app"
18-
},
1916
"browserslist": {
2017
"production": [
2118
">0.2%",
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import React from 'react';
2-
import GraphiQL from 'graphiql';
2+
import { GraphiQL } from 'graphiql';
3+
import type { Fetcher } from '@graphiql/toolkit';
34
import 'graphiql/graphiql.min.css';
45

5-
const App = () => (
6-
<GraphiQL
7-
fetcher={async graphQLParams => {
8-
const data = await fetch(
9-
'https://swapi-graphql.netlify.app/.netlify/functions/index',
10-
{
11-
method: 'POST',
12-
headers: {
13-
Accept: 'application/json',
14-
'Content-Type': 'application/json',
15-
},
16-
body: JSON.stringify(graphQLParams),
17-
credentials: 'same-origin',
18-
},
19-
);
20-
return data.json().catch(() => data.text());
21-
}}
22-
/>
23-
);
6+
const fetcher: Fetcher = async graphQLParams => {
7+
const data = await fetch(
8+
'https://swapi-graphql.netlify.app/.netlify/functions/index',
9+
{
10+
method: 'POST',
11+
headers: {
12+
Accept: 'application/json',
13+
'Content-Type': 'application/json',
14+
},
15+
body: JSON.stringify(graphQLParams),
16+
credentials: 'same-origin',
17+
},
18+
);
19+
return data.json().catch(() => data.text());
20+
};
21+
22+
const App = () => <GraphiQL fetcher={fetcher} />;
2423

2524
export default App;

examples/graphiql-create-react-app/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { createRoot } from 'react-dom/client';
33
import App from './App';
44
import './index.css';
55

6-
const root = createRoot(document.getElementById('root'));
6+
const root = createRoot(document.getElementById('root')!);
77
root.render(<App />);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.next
1+
.next/

examples/monaco-graphql-nextjs/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Monaco GraphQL Next.js Example
2+
3+
## Getting Started
4+
15
This is a working example of `monaco-editor` and `monaco-graphql` using
26
`next.js` 13
37

@@ -12,9 +16,9 @@ similar client-side-only loading (with or without dynamic import) should be
1216
fine. For more information on loading `monaco-editor` in esm contexts, you can
1317
[read their docs](https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md)
1418

15-
This work was sponsored by [Grafbase](https://grafbase.com/)!
19+
This work was sponsored by [Grafbase](https://grafbase.com)!
1620

17-
# Setup
21+
## Setup
1822

19-
1. npm install
20-
1. npm start
23+
1. In monorepo root directory run `yarn` and `yarn build`.
24+
1. In this directory run `yarn dev`.

examples/monaco-graphql-nextjs/next.config.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
2-
const { patchWebpackConfig } = require('next-global-css');
1+
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
2+
import { patchWebpackConfig } from 'next-global-css';
33

44
/** @type {import('next').NextConfig} */
55
const nextConfig = {
6-
reactStrictMode: true,
6+
eslint: {
7+
ignoreDuringBuilds: true,
8+
},
79
trailingSlash: true,
810
webpack(config, options) {
911
// this fixes some issues with loading web workers
@@ -13,7 +15,6 @@ const nextConfig = {
1315
patchWebpackConfig(config, options);
1416
config.resolve.alias = {
1517
...config.resolve.alias,
16-
1718
// this solves a bug with more recent `monaco-editor` versions in next.js,
1819
// where vscode contains a version of `marked` with modules pre-transpiled, which seems to break the build.
1920
//
@@ -36,7 +37,7 @@ const nextConfig = {
3637
label: 'graphql',
3738
worker: {
3839
id: 'graphql',
39-
entry: require.resolve('monaco-graphql/esm/graphql.worker.js'),
40+
entry: 'monaco-graphql/esm/graphql.worker.js',
4041
},
4142
},
4243
],
@@ -49,4 +50,4 @@ const nextConfig = {
4950
},
5051
};
5152

52-
module.exports = nextConfig;
53+
export default nextConfig;
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
{
2-
"name": "next-monaco-example",
3-
"version": "0.1.0",
2+
"name": "example-monaco-graphql-nextjs",
3+
"version": "0.0.0",
44
"private": true,
5+
"type": "module",
56
"scripts": {
6-
"dev": "next dev",
7+
"dev": "next",
78
"build": "next build",
8-
"start": "next start",
9-
"lint": "next lint"
9+
"start": "next start"
1010
},
1111
"dependencies": {
12-
"@graphiql/toolkit": "^0.8.0",
13-
"@types/node": "18.13.0",
14-
"@types/react": "18.0.28",
15-
"@types/react-dom": "18.0.11",
16-
"eslint": "8.34.0",
17-
"eslint-config-next": "13.1.6",
12+
"prettier": "3.0.0-alpha.12",
13+
"@graphiql/toolkit": "^0.8.4",
1814
"graphql": "^16.6.0",
19-
"graphql-ws": "^5.11.3",
15+
"graphql-ws": "^5.5.5",
2016
"jsonc-parser": "^3.2.0",
2117
"marked": "^4.2.12",
22-
"monaco-editor": "^0.35.0",
18+
"monaco-editor": "^0.39.0",
2319
"monaco-editor-webpack-plugin": "^7.0.1",
24-
"monaco-graphql": "^1.1.7",
25-
"next": "13.1.6",
26-
"next-global-css": "^1.3.1",
27-
"prettier": "^2.8.4",
20+
"monaco-graphql": "^1.2.4",
21+
"next": "13.4.7",
2822
"react": "18.2.0",
29-
"react-dom": "18.2.0",
30-
"typescript": "4.9.5"
23+
"react-dom": "18.2.0"
24+
},
25+
"devDependencies": {
26+
"@types/node": "18.16.18",
27+
"@types/react": "18.2.14",
28+
"next-global-css": "1.3.1",
29+
"typescript": "5.1.3"
3130
}
3231
}

examples/monaco-graphql-nextjs/public/next.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)