Skip to content

Commit 0bde94d

Browse files
committed
further migrations
1 parent 3ef9096 commit 0bde94d

File tree

26 files changed

+117
-37
lines changed

26 files changed

+117
-37
lines changed

examples/graphql-file-upload-example/frontend/package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@apollo/client": "3.7.0",
67
"@testing-library/jest-dom": "5.16.5",
78
"@testing-library/react": "13.4.0",
89
"@testing-library/user-event": "14.4.3",
9-
"@apollo/client": "3.7.0",
10-
"apollo-upload-client": "17.0.0",
10+
"apollo-upload-client": "^17.0.0",
1111
"graphql": "16.6.0",
1212
"react": "18.2.0",
1313
"react-dom": "18.2.0",
1414
"react-scripts": "5.0.1",
1515
"web-vitals": "3.0.3"
1616
},
17+
"devDependencies": {
18+
"@types/apollo-upload-client": "17.0.1",
19+
"@types/jest": "27.5.2",
20+
"@types/node": "16.11.65",
21+
"@types/react": "18.0.21",
22+
"@types/react-dom": "18.0.6",
23+
"typescript": "4.8.4"
24+
},
1725
"scripts": {
1826
"start": "react-scripts start",
1927
"build": "react-scripts build",
@@ -31,5 +39,11 @@
3139
"last 1 firefox version",
3240
"last 1 safari version"
3341
]
42+
},
43+
"eslintConfig": {
44+
"extends": [
45+
"react-app",
46+
"react-app/jest"
47+
]
3448
}
3549
}

examples/graphql-file-upload-example/frontend/src/Files.js renamed to examples/graphql-file-upload-example/frontend/src/Files.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { useMutation, useQuery } from '@apollo/client';
22
import { GET_FILES, DELETE_FILE } from './queries';
33

4+
export type FileType = {
5+
filename: string;
6+
thumbnailImage: any;
7+
};
8+
9+
export type FilesType = {
10+
files: FileType[];
11+
};
12+
413
export default function Files() {
5-
const { loading, error, data } = useQuery(GET_FILES);
14+
const { loading, error, data } = useQuery<FilesType>(GET_FILES);
615
const [deleteFile] = useMutation(DELETE_FILE);
716

8-
if (loading) return 'Loading...';
9-
if (error) return `Error! ${error.message}`;
17+
if (loading) return <p>Loading...</p>;
18+
if (error) return <p>{`Error! ${error.message}`}</p>;
1019

1120
return (
1221
<ul>
13-
{data?.files.map(({ filename, thumbnailImage }) => {
22+
{data?.files.map(({ filename, thumbnailImage }: { filename: any; thumbnailImage: any }) => {
1423
const extension = filename.split('.').pop();
1524
const uri = `data:image/${extension};base64,${thumbnailImage}`;
1625
return (
@@ -23,14 +32,14 @@ export default function Files() {
2332
filename,
2433
},
2534
update(cache) {
26-
const data = cache.readQuery({
35+
const data = cache.readQuery<FilesType>({
2736
query: GET_FILES,
2837
});
2938
cache.writeQuery({
3039
query: GET_FILES,
3140
data: {
3241
...data,
33-
files: data.files.filter(image => image.filename !== filename),
42+
files: data?.files.filter(image => image.filename !== filename),
3443
},
3544
});
3645
},

examples/graphql-file-upload-example/frontend/src/UploadFile.js renamed to examples/graphql-file-upload-example/frontend/src/UploadFile.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useRef, useState } from 'react';
22
import { useMutation } from '@apollo/client';
33
import { GET_FILES, UPLOAD_FILE } from './queries';
4+
import { FileType, FilesType } from './Files';
45

56
export default function UploadFile() {
67
const [uploadFile] = useMutation(UPLOAD_FILE);
7-
const [file, setFile] = useState();
8-
const inputRef = useRef(null);
8+
const [file, setFile] = useState<FileType>();
9+
const inputRef = useRef<FilesType & HTMLInputElement>(null);
910
const onSelectFile = () => {
10-
setFile(inputRef.current.files[0]);
11+
setFile(inputRef.current!.files[0]);
1112
};
1213
return (
1314
<form
@@ -18,7 +19,7 @@ export default function UploadFile() {
1819
upload: file,
1920
},
2021
update(cache, { data: newImage }) {
21-
const data = cache.readQuery({
22+
const data = cache.readQuery<FilesType>({
2223
query: GET_FILES,
2324
});
2425
const existingFiles = data?.files || [];
@@ -31,7 +32,7 @@ export default function UploadFile() {
3132
});
3233
},
3334
});
34-
inputRef.current.value = null;
35+
inputRef.current!.value = '';
3536
}}
3637
>
3738
<input type="file" onBlur={onSelectFile} ref={inputRef} />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

examples/graphql-file-upload-example/frontend/src/reportWebVitals.js renamed to examples/graphql-file-upload-example/frontend/src/reportWebVitals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const reportWebVitals = onPerfEntry => {
1+
import { ReportHandler } from 'web-vitals';
2+
3+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
24
if (onPerfEntry && onPerfEntry instanceof Function) {
35
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
46
getCLS(onPerfEntry);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"noEmit": true,
17+
"jsx": "react-jsx"
18+
},
19+
"include": ["src"]
20+
}

examples/graphql-file-upload-example/resize-image/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { startServer } from './server';
1+
import startServer from './server';
22

33
startServer().then(() => {
44
console.info(`ResizeImage GraphQL API listening on 3002`);

examples/graphql-file-upload-example/resize-image/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createYoga, createSchema } from 'graphql-yoga';
22
import { createServer } from 'http';
33
import sharp from 'sharp';
44

5-
export function startServer() {
5+
export default function startServer() {
66
const yoga = createYoga({
77
schema: createSchema({
88
typeDefs: /* GraphQL */ `

examples/graphql-file-upload-example/test/graphql-file-upload-example.test.js renamed to examples/graphql-file-upload-example/test/graphql-file-upload-example.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const startUploadFilesServer = require('../upload-files/server');
2-
const startResizeImageServer = require('../resize-image/server');
3-
const { File } = require('@whatwg-node/fetch');
4-
const { findAndParseConfig } = require('@graphql-mesh/cli');
5-
const { join } = require('path');
6-
const { getMesh } = require('@graphql-mesh/runtime');
1+
import startUploadFilesServer from '../upload-files/server';
2+
import startResizeImageServer from '../resize-image/server';
3+
import { File } from '@whatwg-node/fetch';
4+
import { findAndParseConfig } from '@graphql-mesh/cli';
5+
import { join } from 'path';
6+
import { getMesh } from '@graphql-mesh/runtime';
77

88
describe('Upload Example', () => {
99
let stopUploadFilesServer;

examples/graphql-file-upload-example/upload-files/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { startServer } from './server';
1+
import startServer from './server';
22

33
startServer().then(() => {
44
console.info(`UploadFiles GraphQL API listening on 3001`);

examples/graphql-file-upload-example/upload-files/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!existsSync(FILES_DIR)) {
1010
mkdirSync(FILES_DIR);
1111
}
1212

13-
export function startServer() {
13+
export default function startServer() {
1414
const yoga = createYoga({
1515
schema: createSchema({
1616
typeDefs: /* GraphQL */ `
File renamed without changes.

examples/hello-world-esm/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"private": true,
88
"scripts": {
99
"prestart": "mesh build --fileType js",
10-
"start": "node index.js"
10+
"start": "ts-node index.ts"
1111
},
1212
"dependencies": {
1313
"@graphql-mesh/cli": "0.78.33",
@@ -16,6 +16,8 @@
1616
"graphql": "16.6.0"
1717
},
1818
"devDependencies": {
19-
"jest": "29.2.0"
19+
"jest": "29.2.0",
20+
"ts-node": "10.9.1",
21+
"typescript": "4.8.4"
2022
}
2123
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"rootDir": "./",
6+
"esModuleInterop": true
7+
}
8+
}

examples/json-schema-example/scripts/generate-bundle.js

Whitespace-only changes.

examples/json-schema-fhir/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"private": true,
66
"scripts": {
7-
"download-fhir-schema": "node scripts/download-fhir-schema.js",
7+
"download-fhir-schema": "ts-node scripts/download-fhir-schema.ts",
88
"build": "mesh build",
99
"start": "mesh dev",
1010
"start:prod": "mesh start"
@@ -14,5 +14,10 @@
1414
"@graphql-mesh/json-schema": "0.35.25",
1515
"graphql": "16.6.0",
1616
"unzip-stream": "0.3.1"
17+
},
18+
"devDependencies": {
19+
"@types/unzip-stream": "0.3.1",
20+
"ts-node": "10.9.1",
21+
"typescript": "4.8.4"
1722
}
1823
}

examples/json-schema-fhir/scripts/download-fhir-schema.js renamed to examples/json-schema-fhir/scripts/download-fhir-schema.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
const fetch = require('node-fetch');
2-
const { createWriteStream, existsSync } = require('fs');
3-
const { join } = require('path');
4-
const unzip = require('unzip-stream');
1+
import fetch from 'node-fetch';
2+
import { createWriteStream } from 'fs';
3+
import { join } from 'path';
4+
import unzip, { Entry } from 'unzip-stream';
55

66
async function downloadFhirSchema() {
77
const res = await fetch('https://www.hl7.org/fhir/fhir.schema.json.zip');
88
await new Promise((resolve, reject) => {
99
res.body
1010
.pipe(unzip.Parse())
11-
.on('entry', entry => entry.pipe(createWriteStream(join(__dirname, `../${entry.path}`))))
11+
.on('entry', (entry: Entry) => entry.pipe(createWriteStream(join(__dirname, `../${entry.path}`))))
1212
.on('finish', resolve);
1313
res.body.on('error', reject);
1414
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"rootDir": "./",
6+
"esModuleInterop": true
7+
}
8+
}

examples/json-schema-subscriptions/api.js renamed to examples/json-schema-subscriptions/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const express = require('express');
2-
const { fetch } = require('@whatwg-node/fetch');
3-
const bodyParser = require('body-parser');
1+
import express from 'express';
2+
import { fetch } from '@whatwg-node/fetch';
3+
import bodyParser from 'body-parser';
44

55
const app = express();
66
app.use(bodyParser.json());

examples/json-schema-subscriptions/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"start": "concurrently \"yarn start:api\" \"yarn start:mesh\"",
7-
"start:api": "node api.js",
7+
"start:api": "ts-node api.ts",
88
"start:mesh": "mesh dev"
99
},
1010
"dependencies": {
@@ -17,6 +17,8 @@
1717
"@whatwg-node/fetch": "0.4.7"
1818
},
1919
"devDependencies": {
20-
"concurrently": "7.4.0"
20+
"concurrently": "7.4.0",
21+
"ts-node": "10.9.1",
22+
"typescript": "4.8.4"
2123
}
2224
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"rootDir": "./",
6+
"esModuleInterop": true
7+
}
8+
}

0 commit comments

Comments
 (0)