diff --git a/.changeset/flat-goats-taste.md b/.changeset/flat-goats-taste.md new file mode 100644 index 00000000..a009d581 --- /dev/null +++ b/.changeset/flat-goats-taste.md @@ -0,0 +1,5 @@ +--- +'fuse': patch +--- + +Ensure we refresh the `schema.graphql` diff --git a/examples/standalone/schema.graphql b/examples/standalone/schema.graphql index 35d17aa3..bd06dc90 100644 --- a/examples/standalone/schema.graphql +++ b/examples/standalone/schema.graphql @@ -13,7 +13,7 @@ type Launch implements Node { id: ID! image: String! launchDate: String! - name: String! + nam: String! rocket: Rocket! site: Site! } diff --git a/examples/standalone/src/fuse/introspection.ts b/examples/standalone/src/fuse/introspection.ts index fa6213fa..fd02b9ac 100644 --- a/examples/standalone/src/fuse/introspection.ts +++ b/examples/standalone/src/fuse/introspection.ts @@ -87,7 +87,7 @@ const introspection = { args: [], }, { - name: 'name', + name: 'nam', type: { kind: 'NON_NULL', ofType: { diff --git a/packages/core/src/cli.ts b/packages/core/src/cli.ts index 30c1e948..6bc7c7db 100644 --- a/packages/core/src/cli.ts +++ b/packages/core/src/cli.ts @@ -138,6 +138,7 @@ prog } const baseDirectory = process.cwd() + const isUsingTada = opts.client && (await isUsingGraphQLTada(baseDirectory)) if (opts.server) { let yoga @@ -171,6 +172,13 @@ prog server.watcher.on('change', async (file) => { if (file.includes('types/')) { + if (isUsingTada) { + setTimeout(() => { + fetch( + `http://localhost:${opts.port}/api/graphql?query={__typename}`, + ) + }, 500) + } server.restart() } }) @@ -180,7 +188,7 @@ prog } if (opts.client) { - if (!(await isUsingGraphQLTada(baseDirectory))) { + if (!isUsingTada) { await boostrapCodegen(opts.schema, true) } else { const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src')) diff --git a/packages/core/src/next/plugin.ts b/packages/core/src/next/plugin.ts index e5dcf658..6adcc8ba 100644 --- a/packages/core/src/next/plugin.ts +++ b/packages/core/src/next/plugin.ts @@ -1,10 +1,11 @@ import path from 'path' import { generate, CodegenContext } from '@graphql-codegen/cli' -import { existsSync, promises as fs } from 'fs' +import { existsSync, promises as fs, watch } from 'fs' import { resolve } from 'path' import { DateTimeResolver, JSONResolver } from 'graphql-scalars' import { isUsingGraphQLTada, tadaGqlContents } from '../utils/gql-tada' +import { sign } from 'crypto' interface Options { port?: number @@ -19,13 +20,52 @@ export function nextFusePlugin(options: Options = {}) { isUsingGraphQLTada(process.cwd()).then((isUsing) => { boostrapFuse(isUsing) try { - setTimeout(() => { - try { - if (!isUsing) { + if (isUsing) { + let baseDirectory = process.cwd() + const hasSrcDir = existsSync(resolve(baseDirectory, 'src')) + if (hasSrcDir) { + baseDirectory = resolve(baseDirectory, 'src') + } + + setTimeout(() => { + fetch( + `http://localhost:${options.port || 3000}/api/${ + options.path || 'fuse' + }?query={__typename}`, + ) + }, 1000) + const watcher = watch( + resolve(baseDirectory, 'types'), + { recursive: true }, + () => { + setTimeout(() => { + fetch( + `http://localhost:${options.port || 3000}/api/${ + options.path || 'fuse' + }?query={__typename}`, + ) + }, 1000) + }, + ) + + function exitHandler() { + try { + watcher.close() + } catch (e) {} + } + + process.on('exit', exitHandler) + process.on('SIGINT', exitHandler) + process.on('SIGUSR1', exitHandler) + process.on('SIGUSR2', exitHandler) + process.on('uncaughtException', exitHandler) + } else { + setTimeout(() => { + try { boostrapCodegen(options.port || 3000, options.path || 'fuse') - } - } catch (e) {} - }, 1000) + } catch (e) {} + }, 1000) + } } catch (e) {} }) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e323523a..609b8ce4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,6 +64,46 @@ importers: specifier: ^5 version: 5.2.2 + examples/my-app: + dependencies: + fuse: + specifier: workspace:* + version: link:../../packages/core + gql.tada: + specifier: 1.0.1 + version: 1.0.1(graphql@16.8.1) + graphql: + specifier: ^16.8.1 + version: 16.8.1 + next: + specifier: 14.0.4 + version: 14.0.4(react-dom@18.2.0)(react@18.2.0) + react: + specifier: ^18 + version: 18.2.0 + react-dom: + specifier: ^18 + version: 18.2.0(react@18.2.0) + devDependencies: + '@0no-co/graphqlsp': + specifier: ^1.0.2 + version: 1.0.2 + '@graphql-typed-document-node/core': + specifier: ^3.2.0 + version: 3.2.0(graphql@16.8.1) + '@types/node': + specifier: ^20 + version: 20.10.3 + '@types/react': + specifier: ^18 + version: 18.2.48 + '@types/react-dom': + specifier: ^18 + version: 18.2.15 + typescript: + specifier: ^5 + version: 5.3.2 + examples/spacex: dependencies: '@graphql-typed-document-node/core': @@ -3932,6 +3972,10 @@ packages: /@next/env@14.0.3: resolution: {integrity: sha512-7xRqh9nMvP5xrW4/+L0jgRRX+HoNRGnfJpD+5Wq6/13j3dsdzxO3BCXn7D3hMqsDb+vjZnJq+vI7+EtgrYZTeA==} + /@next/env@14.0.4: + resolution: {integrity: sha512-irQnbMLbUNQpP1wcE5NstJtbuA/69kRfzBrpAD7Gsn8zm/CY6YQYc3HQBz8QPxwISG26tIm5afvvVbu508oBeQ==} + dev: false + /@next/eslint-plugin-next@14.0.3: resolution: {integrity: sha512-j4K0n+DcmQYCVnSAM+UByTVfIHnYQy2ODozfQP+4RdwtRDfobrIvKq1K4Exb2koJ79HSSa7s6B2SA8T/1YR3RA==} dependencies: @@ -3946,6 +3990,15 @@ packages: requiresBuild: true optional: true + /@next/swc-darwin-arm64@14.0.4: + resolution: {integrity: sha512-mF05E/5uPthWzyYDyptcwHptucf/jj09i2SXBPwNzbgBNc+XnwzrL0U6BmPjQeOL+FiB+iG1gwBeq7mlDjSRPg==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + /@next/swc-darwin-x64@14.0.3: resolution: {integrity: sha512-RkTf+KbAD0SgYdVn1XzqE/+sIxYGB7NLMZRn9I4Z24afrhUpVJx6L8hsRnIwxz3ERE2NFURNliPjJ2QNfnWicQ==} engines: {node: '>= 10'} @@ -3954,6 +4007,15 @@ packages: requiresBuild: true optional: true + /@next/swc-darwin-x64@14.0.4: + resolution: {integrity: sha512-IZQ3C7Bx0k2rYtrZZxKKiusMTM9WWcK5ajyhOZkYYTCc8xytmwSzR1skU7qLgVT/EY9xtXDG0WhY6fyujnI3rw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + /@next/swc-linux-arm64-gnu@14.0.3: resolution: {integrity: sha512-3tBWGgz7M9RKLO6sPWC6c4pAw4geujSwQ7q7Si4d6bo0l6cLs4tmO+lnSwFp1Tm3lxwfMk0SgkJT7EdwYSJvcg==} engines: {node: '>= 10'} @@ -3962,6 +4024,15 @@ packages: requiresBuild: true optional: true + /@next/swc-linux-arm64-gnu@14.0.4: + resolution: {integrity: sha512-VwwZKrBQo/MGb1VOrxJ6LrKvbpo7UbROuyMRvQKTFKhNaXjUmKTu7wxVkIuCARAfiI8JpaWAnKR+D6tzpCcM4w==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@next/swc-linux-arm64-musl@14.0.3: resolution: {integrity: sha512-v0v8Kb8j8T23jvVUWZeA2D8+izWspeyeDGNaT2/mTHWp7+37fiNfL8bmBWiOmeumXkacM/AB0XOUQvEbncSnHA==} engines: {node: '>= 10'} @@ -3970,6 +4041,15 @@ packages: requiresBuild: true optional: true + /@next/swc-linux-arm64-musl@14.0.4: + resolution: {integrity: sha512-8QftwPEW37XxXoAwsn+nXlodKWHfpMaSvt81W43Wh8dv0gkheD+30ezWMcFGHLI71KiWmHK5PSQbTQGUiidvLQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@next/swc-linux-x64-gnu@14.0.3: resolution: {integrity: sha512-VM1aE1tJKLBwMGtyBR21yy+STfl0MapMQnNrXkxeyLs0GFv/kZqXS5Jw/TQ3TSUnbv0QPDf/X8sDXuMtSgG6eg==} engines: {node: '>= 10'} @@ -3978,6 +4058,15 @@ packages: requiresBuild: true optional: true + /@next/swc-linux-x64-gnu@14.0.4: + resolution: {integrity: sha512-/s/Pme3VKfZAfISlYVq2hzFS8AcAIOTnoKupc/j4WlvF6GQ0VouS2Q2KEgPuO1eMBwakWPB1aYFIA4VNVh667A==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@next/swc-linux-x64-musl@14.0.3: resolution: {integrity: sha512-64EnmKy18MYFL5CzLaSuUn561hbO1Gk16jM/KHznYP3iCIfF9e3yULtHaMy0D8zbHfxset9LTOv6cuYKJgcOxg==} engines: {node: '>= 10'} @@ -3986,6 +4075,15 @@ packages: requiresBuild: true optional: true + /@next/swc-linux-x64-musl@14.0.4: + resolution: {integrity: sha512-m8z/6Fyal4L9Bnlxde5g2Mfa1Z7dasMQyhEhskDATpqr+Y0mjOBZcXQ7G5U+vgL22cI4T7MfvgtrM2jdopqWaw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@next/swc-win32-arm64-msvc@14.0.3: resolution: {integrity: sha512-WRDp8QrmsL1bbGtsh5GqQ/KWulmrnMBgbnb+59qNTW1kVi1nG/2ndZLkcbs2GX7NpFLlToLRMWSQXmPzQm4tog==} engines: {node: '>= 10'} @@ -3994,6 +4092,15 @@ packages: requiresBuild: true optional: true + /@next/swc-win32-arm64-msvc@14.0.4: + resolution: {integrity: sha512-7Wv4PRiWIAWbm5XrGz3D8HUkCVDMMz9igffZG4NB1p4u1KoItwx9qjATHz88kwCEal/HXmbShucaslXCQXUM5w==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@next/swc-win32-ia32-msvc@14.0.3: resolution: {integrity: sha512-EKffQeqCrj+t6qFFhIFTRoqb2QwX1mU7iTOvMyLbYw3QtqTw9sMwjykyiMlZlrfm2a4fA84+/aeW+PMg1MjuTg==} engines: {node: '>= 10'} @@ -4002,6 +4109,15 @@ packages: requiresBuild: true optional: true + /@next/swc-win32-ia32-msvc@14.0.4: + resolution: {integrity: sha512-zLeNEAPULsl0phfGb4kdzF/cAVIfaC7hY+kt0/d+y9mzcZHsMS3hAS829WbJ31DkSlVKQeHEjZHIdhN+Pg7Gyg==} + engines: {node: '>= 10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@next/swc-win32-x64-msvc@14.0.3: resolution: {integrity: sha512-ERhKPSJ1vQrPiwrs15Pjz/rvDHZmkmvbf/BjPN/UCOI++ODftT0GtasDPi0j+y6PPJi5HsXw+dpRaXUaw4vjuQ==} engines: {node: '>= 10'} @@ -4010,6 +4126,15 @@ packages: requiresBuild: true optional: true + /@next/swc-win32-x64-msvc@14.0.4: + resolution: {integrity: sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -10262,6 +10387,46 @@ packages: - '@babel/core' - babel-plugin-macros + /next@14.0.4(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-qbwypnM7327SadwFtxXnQdGiKpkuhaRLE2uq62/nRul9cj9KhQ5LhHmlziTNqUidZotw/Q1I9OjirBROdUJNgA==} + engines: {node: '>=18.17.0'} + hasBin: true + peerDependencies: + '@opentelemetry/api': ^1.1.0 + react: ^18.2.0 + react-dom: ^18.2.0 + sass: ^1.3.0 + peerDependenciesMeta: + '@opentelemetry/api': + optional: true + sass: + optional: true + dependencies: + '@next/env': 14.0.4 + '@swc/helpers': 0.5.2 + busboy: 1.6.0 + caniuse-lite: 1.0.30001562 + graceful-fs: 4.2.11 + postcss: 8.4.31 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + styled-jsx: 5.1.1(@babel/core@7.23.3)(react@18.2.0) + watchpack: 2.4.0 + optionalDependencies: + '@next/swc-darwin-arm64': 14.0.4 + '@next/swc-darwin-x64': 14.0.4 + '@next/swc-linux-arm64-gnu': 14.0.4 + '@next/swc-linux-arm64-musl': 14.0.4 + '@next/swc-linux-x64-gnu': 14.0.4 + '@next/swc-linux-x64-musl': 14.0.4 + '@next/swc-win32-arm64-msvc': 14.0.4 + '@next/swc-win32-ia32-msvc': 14.0.4 + '@next/swc-win32-x64-msvc': 14.0.4 + transitivePeerDependencies: + - '@babel/core' + - babel-plugin-macros + dev: false + /nextra-theme-docs@2.13.2(next@14.0.3)(nextra@2.13.2)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-yE4umXaImp1/kf/sFciPj2+EFrNSwd9Db26hi98sIIiujzGf3+9eUgAz45vF9CwBw50FSXxm1QGRcY+slQ4xQQ==} peerDependencies: