From 905bcf3e86e6d95b5fca27a1398f958a742bf9f4 Mon Sep 17 00:00:00 2001 From: Conrawl Rogers Date: Sun, 16 Oct 2022 19:05:08 -0400 Subject: [PATCH] fix!: improved multi client support BREAKING CHANGE: graphql operations can no longer be prefixed with a client name --- docs/content/2.advanced/2.multiple-clients.md | 10 +- package.json | 6 +- pnpm-lock.yaml | 285 +++++++++--------- src/context.ts | 77 ++--- src/generate.ts | 137 +++------ src/module.ts | 26 +- src/runtime/composables/index.ts | 36 ++- src/types.d.ts | 9 - test/fixtures/multi-client/nuxt.config.ts | 4 +- .../queries/countries/continents.gql | 6 + .../multi-client/queries/demo.rmorty.gql | 5 + .../multi-client/queries/demo.spacex.gql | 5 + .../multi-client/queries/dual_clients.gql | 14 - .../queries/rmorty/characters.gql | 8 + .../multi-client/queries/rmorty/ep.gql | 2 +- .../multi-client/queries/spacex/demo.gql | 6 + .../multi-client/queries/spacex/mission.gql | 2 +- .../multi-client/queries/todos/todos.gql | 6 + 18 files changed, 294 insertions(+), 350 deletions(-) create mode 100644 test/fixtures/multi-client/queries/countries/continents.gql create mode 100644 test/fixtures/multi-client/queries/demo.rmorty.gql create mode 100644 test/fixtures/multi-client/queries/demo.spacex.gql delete mode 100644 test/fixtures/multi-client/queries/dual_clients.gql create mode 100644 test/fixtures/multi-client/queries/rmorty/characters.gql create mode 100644 test/fixtures/multi-client/queries/spacex/demo.gql create mode 100644 test/fixtures/multi-client/queries/todos/todos.gql diff --git a/docs/content/2.advanced/2.multiple-clients.md b/docs/content/2.advanced/2.multiple-clients.md index 0da4ed3..4248689 100644 --- a/docs/content/2.advanced/2.multiple-clients.md +++ b/docs/content/2.advanced/2.multiple-clients.md @@ -64,17 +64,17 @@ When using multiple clients, you must specify the client that your GraphQL Opera There are two methods of associating a client: -1. Prefix the GraphQL Operation name with `_`. +1. Save the GraphQL Document ending with `.gql|graphql`. - ```graphql - query github_viewer { + ```graphql [nuxt-app/queries/example.github.gql] + query viewer { viewer { login } } ``` - Doing so will automatically link the query above to the predefined spacex client **and drop the client prefix** from the autoImported function. This query will be executable in your app by simply calling `GqlViewer()` + Doing so will automatically link the query above to the client named `github`. This query will be executable in your app by simply calling `GqlViewer()` ::alert This method takes precedence and overrides all others. @@ -84,7 +84,7 @@ There are two methods of associating a client: **ie:** Given `./nuxt_app/queries/spacex/launches.gql` - All GraphQL operations within `launches.gql` (*that aren't prefixed with a client name*), will automatically be linked to the client matching the name of the GraphQL document's parent directory ie: `spacex`. + All GraphQL operations within `launches.gql` will automatically be linked to the client matching the name of the GraphQL document's parent directory ie: `spacex`. 4. Lastly, GraphQL documents which don't match any of the aforementioned conventions will be linked to the [default client](#default-client). diff --git a/package.json b/package.json index 885f563..d70efaa 100644 --- a/package.json +++ b/package.json @@ -47,16 +47,12 @@ "@graphql-codegen/typescript": "^2.7.3", "@graphql-codegen/typescript-graphql-request": "^4.5.5", "@graphql-codegen/typescript-operations": "^2.5.3", - "@graphql-tools/graphql-file-loader": "^7.5.5", - "@graphql-tools/load": "^7.7.7", - "@graphql-tools/stitch": "^8.7.13", - "@graphql-tools/wrap": "^9.2.3", "@nuxt/kit": "3.0.0-rc.11", "defu": "^6.1.0", "graphql": "^16.6.0", "graphql-request": "^5.0.0", + "knitwork": "^0.1.2", "ohash": "^0.1.5", - "ohmyfetch": "^0.4.19", "scule": "^0.3.2" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e4054d..bc95f09 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,10 +8,6 @@ importers: '@graphql-codegen/typescript': ^2.7.3 '@graphql-codegen/typescript-graphql-request': ^4.5.5 '@graphql-codegen/typescript-operations': ^2.5.3 - '@graphql-tools/graphql-file-loader': ^7.5.5 - '@graphql-tools/load': ^7.7.7 - '@graphql-tools/stitch': ^8.7.13 - '@graphql-tools/wrap': ^9.2.3 '@nuxt/kit': 3.0.0-rc.11 '@nuxt/module-builder': latest '@nuxt/test-utils': 3.0.0-rc.11 @@ -21,9 +17,9 @@ importers: eslint: ^8.23.1 graphql: ^16.6.0 graphql-request: ^5.0.0 + knitwork: ^0.1.2 nuxt: ^3.0.0-rc.11 ohash: ^0.1.5 - ohmyfetch: ^0.4.19 scule: ^0.3.2 vitest: ^0.24.3 dependencies: @@ -31,19 +27,15 @@ importers: '@graphql-codegen/typescript': 2.7.4_graphql@16.6.0 '@graphql-codegen/typescript-graphql-request': 4.5.6_7lz647nkgovf4mzr2sitna7qte '@graphql-codegen/typescript-operations': 2.5.4_graphql@16.6.0 - '@graphql-tools/graphql-file-loader': 7.5.5_graphql@16.6.0 - '@graphql-tools/load': 7.7.7_graphql@16.6.0 - '@graphql-tools/stitch': 8.7.13_graphql@16.6.0 - '@graphql-tools/wrap': 9.2.3_graphql@16.6.0 '@nuxt/kit': 3.0.0-rc.11 defu: 6.1.0 graphql: 16.6.0 graphql-request: 5.0.0_graphql@16.6.0 + knitwork: 0.1.2 ohash: 0.1.5 - ohmyfetch: 0.4.19 scule: 0.3.2 devDependencies: - '@nuxt/module-builder': 0.1.7 + '@nuxt/module-builder': 0.2.0 '@nuxt/test-utils': 3.0.0-rc.11 '@nuxtjs/eslint-config-typescript': 11.0.0_eslint@8.25.0 '@vitest/coverage-c8': 0.24.3 @@ -918,18 +910,6 @@ packages: - encoding dev: false - /@graphql-tools/batch-delegate/8.4.1_graphql@16.6.0: - resolution: {integrity: sha512-kbDY3p0JKEcIUwb5lCXX647oz07lXbvdfigyzD++Goi7RChutK03MmPKvrrgQwi0SFupRKy1tIJAlExlW83STw==} - peerDependencies: - graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 - dependencies: - '@graphql-tools/delegate': 9.0.8_graphql@16.6.0 - '@graphql-tools/utils': 8.12.0_graphql@16.6.0 - dataloader: 2.1.0 - graphql: 16.6.0 - tslib: 2.4.0 - dev: false - /@graphql-tools/batch-execute/8.5.6_graphql@16.6.0: resolution: {integrity: sha512-33vMvVDLBKsNJVNhcySVXF+zkcRL/GRs1Lt+MxygrYCypcAPpFm+amE2y9vOCFufuaKExIX7Lonnmxu19vPzaQ==} peerDependencies: @@ -1144,22 +1124,6 @@ packages: value-or-promise: 1.0.11 dev: false - /@graphql-tools/stitch/8.7.13_graphql@16.6.0: - resolution: {integrity: sha512-7bKJWT1vJJfg1GKiHd6c3GxdmCX1y4HiMw6nXKKad79wdYC9uxRSBOWFGaGbyIZBkCv4E5ptZioCn65NX+Fmkw==} - peerDependencies: - graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 - dependencies: - '@graphql-tools/batch-delegate': 8.4.1_graphql@16.6.0 - '@graphql-tools/delegate': 9.0.8_graphql@16.6.0 - '@graphql-tools/merge': 8.3.6_graphql@16.6.0 - '@graphql-tools/schema': 9.0.4_graphql@16.6.0 - '@graphql-tools/utils': 8.12.0_graphql@16.6.0 - '@graphql-tools/wrap': 9.2.3_graphql@16.6.0 - graphql: 16.6.0 - tslib: 2.4.0 - value-or-promise: 1.0.11 - dev: false - /@graphql-tools/url-loader/7.16.4_graphql@16.6.0: resolution: {integrity: sha512-7yGrJJNcqVQIplCyVLk7tW2mAgYyZ06FRmCBnzw3B61+aIjFavrm6YlnKkhdqYSYyFmIbVcigdP3vkoYIu23TA==} peerDependencies: @@ -1368,15 +1332,15 @@ packages: transitivePeerDependencies: - supports-color - /@nuxt/module-builder/0.1.7: - resolution: {integrity: sha512-ueTrJhXrKKxGp6VAe2C/nOqTeRoy0qfq9RH2QVl0kq0duDyQHCe1e8dw8yBbYjTlSvfqBPYaraxpX8i2zis2cw==} + /@nuxt/module-builder/0.2.0: + resolution: {integrity: sha512-jzQ10I5n+oAsjvY6ennqmJMU7MneYs79iGXJ6jnBbts4jFuLwWpQbIPpIFfboI4xjHeeTp1quHZyCcpFy+TjAA==} hasBin: true dependencies: consola: 2.15.3 - mlly: 0.3.19 + mlly: 0.5.16 mri: 1.2.0 - pathe: 0.2.0 - unbuild: 0.6.9 + pathe: 0.3.9 + unbuild: 0.9.4 transitivePeerDependencies: - supports-color dev: true @@ -1584,20 +1548,17 @@ packages: slash: 3.0.0 dev: true - /@rollup/plugin-commonjs/21.1.0_rollup@2.79.1: - resolution: {integrity: sha512-6ZtHx3VHIp2ReNNDxHjuUml6ur+WcQ28N1yHgCQwsbNkQg2suhxGMDQGJOn/KuDxKtd1xuZP5xSTwBA4GQ8hbA==} - engines: {node: '>= 8.0.0'} + /@rollup/plugin-alias/4.0.0_rollup@3.2.1: + resolution: {integrity: sha512-fGRWzM2F6wXnzAqn4Db8SdB/2Ree0u2XOQaaTy9mhqA35NmUzJXevMBUcpZywPF2MIUUAw+SKfWogKxFSPh+Qw==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^2.38.3 + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - commondir: 1.0.1 - estree-walker: 2.0.2 - glob: 7.2.3 - is-reference: 1.2.1 - magic-string: 0.25.9 - resolve: 1.22.1 - rollup: 2.79.1 + rollup: 3.2.1 + slash: 4.0.0 dev: true /@rollup/plugin-commonjs/22.0.2_rollup@2.79.1: @@ -1616,6 +1577,24 @@ packages: rollup: 2.79.1 dev: true + /@rollup/plugin-commonjs/23.0.0_rollup@3.2.1: + resolution: {integrity: sha512-JbrTRyDNtLQj/rhl7RFUuYXwQ2fac+33oLDAu2k++WD95zweyo28UAomLVA0JMGx4vmCa7Nw4T6k/1F6lelExg==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.68.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 4.2.1 + commondir: 1.0.1 + estree-walker: 2.0.2 + glob: 8.0.3 + is-reference: 1.2.1 + magic-string: 0.26.7 + rollup: 3.2.1 + dev: true + /@rollup/plugin-inject/4.0.4_rollup@2.79.1: resolution: {integrity: sha512-4pbcU4J/nS+zuHk+c+OL3WtmEQhqxlZ9uqfjQMQDOHOPld7PsCd8k5LWs8h5wjwJN7MgnAn768F2sDxEP4eNFQ==} peerDependencies: @@ -1636,19 +1615,17 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-node-resolve/13.3.0_rollup@2.79.1: - resolution: {integrity: sha512-Lus8rbUo1eEcnS4yTFKLZrVumLPY+YayBdWXgFSHYhTT2iJbMhoaaBL3xl5NCdeRytErGr8tZ0L71BMRmnlwSw==} - engines: {node: '>= 10.0.0'} + /@rollup/plugin-json/5.0.0_rollup@3.2.1: + resolution: {integrity: sha512-LsWDA5wJs/ggzakVuKQhZo7HPRcQZgBa3jWIVxQSFxaRToUGNi8ZBh3+k/gQ+1eInVYJgn4WBRCUkmoDrmmGzw==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^2.42.0 + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - '@types/resolve': 1.17.1 - deepmerge: 4.2.2 - is-builtin-module: 3.2.0 - is-module: 1.0.0 - resolve: 1.22.1 - rollup: 2.79.1 + '@rollup/pluginutils': 4.2.1 + rollup: 3.2.1 dev: true /@rollup/plugin-node-resolve/14.1.0_rollup@2.79.1: @@ -1666,14 +1643,22 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-replace/3.1.0_rollup@2.79.1: - resolution: {integrity: sha512-pA3XRUrSKybVYqmH5TqWNZpGxF+VV+1GrYchKgCNIj2vsSOX7CVm2RCtx8p2nrC7xvkziYyK+lSi74T93MU3YA==} + /@rollup/plugin-node-resolve/15.0.0_rollup@3.2.1: + resolution: {integrity: sha512-iwJbzfTzlzDDQcGmkS7EkCKwe2kSkdBrjX87Fy/KrNjr6UNnLpod0t6X66e502LRe5JJCA4FFqrEscWPnZAkig==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^1.20.0 || ^2.0.0 + rollup: ^2.78.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - magic-string: 0.25.9 - rollup: 2.79.1 + '@rollup/pluginutils': 4.2.1 + '@types/resolve': 1.20.2 + deepmerge: 4.2.2 + is-builtin-module: 3.2.0 + is-module: 1.0.0 + resolve: 1.22.1 + rollup: 3.2.1 dev: true /@rollup/plugin-replace/4.0.0_rollup@2.79.1: @@ -1686,6 +1671,20 @@ packages: rollup: 2.79.1 dev: true + /@rollup/plugin-replace/5.0.0_rollup@3.2.1: + resolution: {integrity: sha512-TiPmjMuBjQM+KLWK16O5TAM/eW4yXBYyQ17FbfeNzBC1t2kzX2aXoa8AlS9XTSmg6/2TNvkER1lMEEeN4Lhavw==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 4.2.1 + magic-string: 0.26.7 + rollup: 3.2.1 + dev: true + /@rollup/plugin-wasm/5.2.0_rollup@2.79.1: resolution: {integrity: sha512-PR3ff67ls2Kr9H04pZ24wJYPZq0YV+UHySpk7OuAJxyc7o5Q8NHFdwi4pfMtJkJkqfN1/QY/nq46SoRDoDvK2w==} engines: {node: '>=10.0.0'} @@ -1714,6 +1713,21 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 + /@rollup/pluginutils/5.0.1_rollup@3.2.1: + resolution: {integrity: sha512-4HaCVEXXuObvcPUaUlLt4faHYHCeQOOWNj8NKFGaRSrw3ZLD0TWeAFZicV9vXjnE2nkNuaVTfTuwAnjR+6uc9A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.0 + estree-walker: 2.0.2 + picomatch: 2.3.1 + rollup: 3.2.1 + dev: true + /@tootallnate/once/2.0.0: resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==} engines: {node: '>= 10'} @@ -1801,6 +1815,10 @@ packages: '@types/node': 18.11.0 dev: true + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + dev: true + /@types/ws/8.5.3: resolution: {integrity: sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==} dependencies: @@ -3196,10 +3214,6 @@ packages: has-property-descriptors: 1.0.0 object-keys: 1.1.1 - /defu/5.0.1: - resolution: {integrity: sha512-EPS1carKg+dkEVy3qNTqIdp2qV7mUP08nIsupfwQpz++slCVRw7qbQyWvSTig+kFPwz2XXp5/kIIkH+CwrJKkQ==} - dev: true - /defu/6.1.0: resolution: {integrity: sha512-pOFYRTIhoKujrmbTRhcW5lYQLBXw/dlTwfI8IguF1QCDJOcJzNH1w+YFjxqy6BAuJrClTy6MUE8q+oKJ2FLsIw==} @@ -3420,10 +3434,6 @@ packages: unbox-primitive: 1.0.2 dev: true - /es-module-lexer/0.9.3: - resolution: {integrity: sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ==} - dev: true - /es-shim-unscopables/1.0.0: resolution: {integrity: sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==} dependencies: @@ -4647,6 +4657,17 @@ packages: once: 1.4.0 path-is-absolute: 1.0.1 + /glob/8.0.3: + resolution: {integrity: sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==} + engines: {node: '>=12'} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 5.1.0 + once: 1.4.0 + dev: true + /globals/11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} engines: {node: '>=4'} @@ -5315,11 +5336,6 @@ packages: resolution: {integrity: sha512-L3BJStEf5NAqNuzrpfbN71dp43mYIcBUlCRea/vdyv5dW/AYa1d4bpelko4SHdY3I6eN9Wzyasxirj1/vv5kmg==} hasBin: true - /joycon/3.1.1: - resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} - engines: {node: '>=10'} - dev: true - /js-sdsl/4.1.5: resolution: {integrity: sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==} dev: true @@ -5846,14 +5862,6 @@ packages: typescript: 4.8.4 dev: true - /mlly/0.3.19: - resolution: {integrity: sha512-zMq5n3cOf4fOzA4WoeulxagbAgMChdev3MgP6K51k7M0u2whTXxupfIY4VVzws4vxkiWhwH1rVQcsw7zDGfRhA==} - dev: true - - /mlly/0.4.3: - resolution: {integrity: sha512-xezyv7hnfFPuiDS3AiJuWs0OxlvooS++3L2lURvmh/1n7UG4O2Ehz9UkwWgg3wyLEPKGVfJLlr2DjjTCl9UJTg==} - dev: true - /mlly/0.5.16: resolution: {integrity: sha512-LaJ8yuh4v0zEmge/g3c7jjFlhoCPfQn6RCjXgm9A0Qiuochq4BcuOxVfWmdnCoLTlg2MV+hqhOek+W2OhG0Lwg==} dependencies: @@ -5980,6 +5988,7 @@ packages: /node-fetch-native/0.1.7: resolution: {integrity: sha512-hps7dFJM0IEF056JftDSSjWDAwW9v2clwHoUJiHyYgl+ojoqjKyWybljMlpTmlC1O+864qovNlRLyAIjRxu9Ag==} + dev: true /node-fetch/2.6.7: resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==} @@ -6199,6 +6208,7 @@ packages: node-fetch-native: 0.1.7 ufo: 0.8.5 undici: 5.11.0 + dev: true /on-finished/2.4.1: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} @@ -6801,11 +6811,6 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /pretty-bytes/5.6.0: - resolution: {integrity: sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==} - engines: {node: '>=6'} - dev: true - /pretty-bytes/6.0.0: resolution: {integrity: sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg==} engines: {node: ^14.13.1 || >=16.0.0} @@ -7041,38 +7046,20 @@ packages: glob: 7.2.3 dev: true - /rollup-plugin-dts/4.2.3_gypgyaqhine6mwjfvh7icfhviq: - resolution: {integrity: sha512-jlcpItqM2efqfIiKzDB/IKOS9E9fDvbkJSGw5GtK/PqPGS9eC3R3JKyw2VvpTktZA+TNgJRMu1NTv244aTUzzQ==} - engines: {node: '>=v12.22.12'} + /rollup-plugin-dts/5.0.0_dyg53bw4sastqlnidv2dvxaeae: + resolution: {integrity: sha512-OO8ayCvuJCKaQSShyVTARxGurVVk4ulzbuvz+0zFd1f93vlnWFU5pBMT7HFeS6uj7MvvZLx4kUAarGATSU1+Ng==} + engines: {node: '>=v14'} peerDependencies: - rollup: ^2.55 + rollup: ^3.0.0 typescript: ^4.1 dependencies: magic-string: 0.26.7 - rollup: 2.79.1 + rollup: 3.2.1 typescript: 4.8.4 optionalDependencies: '@babel/code-frame': 7.18.6 dev: true - /rollup-plugin-esbuild/4.10.1_gkkadhp4kuvg7lmep2ttfihjii: - resolution: {integrity: sha512-/ymcRB283zjFp1JTBXO8ekxv0c9vRc2L6OTljghsLthQ4vqeDSDWa9BVz1tHiVrx6SbUnUpDPLC0K/MXK7j5TA==} - engines: {node: '>=12'} - peerDependencies: - esbuild: '>=0.10.1' - rollup: ^1.20.0 || ^2.0.0 - dependencies: - '@rollup/pluginutils': 4.2.1 - debug: 4.3.4 - es-module-lexer: 0.9.3 - esbuild: 0.14.54 - joycon: 3.1.1 - jsonc-parser: 3.2.0 - rollup: 2.79.1 - transitivePeerDependencies: - - supports-color - dev: true - /rollup-plugin-terser/7.0.2_rollup@2.79.1: resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==} peerDependencies: @@ -7123,6 +7110,14 @@ packages: fsevents: 2.3.2 dev: true + /rollup/3.2.1: + resolution: {integrity: sha512-Y9lBWYY7pOiWhJbwMEnLicDuTu9IqjJb5jJM88L8O5rdreJrX1j9WhriMHQSOwVYPFg1xkLoXQyDfQ2U6Ejzyg==} + engines: {node: '>=14.18.0', npm: '>=8.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.2 + dev: true + /run-async/2.4.1: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} engines: {node: '>=0.12.0'} @@ -7164,10 +7159,6 @@ packages: resolution: {integrity: sha512-MuCAyrGZcTLfQoH2XoBlQ8C6bzwN88XT/0slOGz0pn8+gIP85BOAfYa44ZXQUTOwRwPU0QvgU+V+OSajl/59Xg==} dev: false - /scule/0.2.1: - resolution: {integrity: sha512-M9gnWtn3J0W+UhJOHmBxBTwv8mZCan5i1Himp60t6vvZcor0wr+IM0URKmIglsWJ7bRujNAVVN77fp+uZaWoKg==} - dev: true - /scule/0.3.2: resolution: {integrity: sha512-zIvPdjOH8fv8CgrPT5eqtxHQXmPNnV/vHJYffZhE43KZkvULvpCTvOt1HPlFaCZx287INL9qaqrZg34e8NgI4g==} @@ -7790,37 +7781,37 @@ packages: which-boxed-primitive: 1.0.2 dev: true - /unbuild/0.6.9: - resolution: {integrity: sha512-IALhVj6cLWAxFqX5qcuR932Y3OKFgWcZXPeQ0qU1YAuBucWzpY171GHMi+rXot3C4V7JwD0khGmjvu41E980mQ==} + /unbuild/0.9.4: + resolution: {integrity: sha512-IkKPqzazcCNfwTSs5bDRS2bOvg1Zh9gPYQq/ruVarCoM4f7KXclSrcb0jyJiSU/5qhakZ8K5B2CzwX4ZaaVKdQ==} hasBin: true dependencies: - '@rollup/plugin-alias': 3.1.9_rollup@2.79.1 - '@rollup/plugin-commonjs': 21.1.0_rollup@2.79.1 - '@rollup/plugin-json': 4.1.0_rollup@2.79.1 - '@rollup/plugin-node-resolve': 13.3.0_rollup@2.79.1 - '@rollup/plugin-replace': 3.1.0_rollup@2.79.1 - '@rollup/pluginutils': 4.2.1 + '@rollup/plugin-alias': 4.0.0_rollup@3.2.1 + '@rollup/plugin-commonjs': 23.0.0_rollup@3.2.1 + '@rollup/plugin-json': 5.0.0_rollup@3.2.1 + '@rollup/plugin-node-resolve': 15.0.0_rollup@3.2.1 + '@rollup/plugin-replace': 5.0.0_rollup@3.2.1 + '@rollup/pluginutils': 5.0.1_rollup@3.2.1 chalk: 5.1.2 consola: 2.15.3 - defu: 5.0.1 - esbuild: 0.14.54 + defu: 6.1.0 + esbuild: 0.15.11 + globby: 13.1.2 hookable: 5.4.1 jiti: 1.16.0 - magic-string: 0.25.9 + magic-string: 0.26.7 mkdirp: 1.0.4 mkdist: 0.3.13_typescript@4.8.4 - mlly: 0.4.3 + mlly: 0.5.16 mri: 1.2.0 - pathe: 0.2.0 + pathe: 0.3.9 pkg-types: 0.3.5 - pretty-bytes: 5.6.0 + pretty-bytes: 6.0.0 rimraf: 3.0.2 - rollup: 2.79.1 - rollup-plugin-dts: 4.2.3_gypgyaqhine6mwjfvh7icfhviq - rollup-plugin-esbuild: 4.10.1_gkkadhp4kuvg7lmep2ttfihjii - scule: 0.2.1 + rollup: 3.2.1 + rollup-plugin-dts: 5.0.0_dyg53bw4sastqlnidv2dvxaeae + scule: 0.3.2 typescript: 4.8.4 - untyped: 0.3.0 + untyped: 0.5.0 transitivePeerDependencies: - supports-color dev: true @@ -7906,10 +7897,6 @@ packages: - utf-8-validate dev: true - /untyped/0.3.0: - resolution: {integrity: sha512-n4M5/T1wWlHFmohk0EhS+yM7W/h5dOtQldOV3MVEbZY1fTy5A47UL8+d8GLW1iwmaAwNrM5ERy3qe1k0T/Yc7A==} - dev: true - /untyped/0.5.0: resolution: {integrity: sha512-2Sre5A1a7G61bjaAKZnSFaVgbJMwwbbYQpJFH69hAYcDfN7kIaktlSphS02XJilz4+/jR1tsJ5MHo1oMoCezxg==} dependencies: diff --git a/src/context.ts b/src/context.ts index 1b52c75..35025c6 100644 --- a/src/context.ts +++ b/src/context.ts @@ -2,19 +2,25 @@ import { promises as fsp } from 'fs' import { parse } from 'graphql' import { upperFirst } from 'scule' import type { Import } from 'unimport' +import { genExport } from 'knitwork' export interface GqlContext { - template?: string + template?: Record fns?: string[] clients?: string[] fnImports?: Import[] generateImports?: () => string generateDeclarations?: () => string clientOps?: Record | null + clientTypes?: Record } export function prepareContext (ctx: GqlContext, prefix: string) { - ctx.fns = ctx.template?.match(/\w+\s*(?=\(variables)/g)?.sort() || [] + ctx.fns = Object.values(ctx.template).reduce((acc, template) => { + const fns = template.match(/\w+\s*(?=\(variables)/g)?.sort() || [] + + return [...acc, ...fns] + }, [] as string[]) const fnName = (fn: string) => prefix + upperFirst(fn) @@ -27,11 +33,16 @@ export function prepareContext (ctx: GqlContext, prefix: string) { return `export const ${name} = (...params) => GqlInstance().handle(${client ? `'${client}'` : ''})['${fn}'](...params)` } - return ` export const ${name}: (...params: Parameters) => ReturnType` + return ` export const ${name}: (...params: Parameters) => ReturnType` } ctx.generateImports = () => [ 'import { useGql } from \'#imports\'', + ...ctx.clients.map(client => `import { getSdk as ${client}GqlSdk } from '#gql/${client}'`), + 'export const GqlSdks = {', + ` default: ${ctx.clients.find(c => c === 'default') || ctx.clients[0]}GqlSdk,`, + ...ctx.clients.map(client => ` ${client}: ${client}GqlSdk,`), + '}', 'const ctx = { instance: null }', 'export const GqlInstance = () => {', ' if (!ctx?.instance) {ctx.instance = useGql()}', @@ -42,17 +53,18 @@ export function prepareContext (ctx: GqlContext, prefix: string) { ].join('\n') ctx.generateDeclarations = () => [ - 'declare module \'#build/gql\' {', + ...ctx.clients.map(client => `import { getSdk as ${client}GqlSdk } from '#gql/${client}'`), + ...Object.entries(ctx.clientTypes || {}).map(([k, v]) => genExport(`#gql/${k}`, v)), + 'declare module \'#gql\' {', ` type GqlClients = '${ctx.clients.join("' | '") || 'default'}'`, - ' type GqlFunc = ReturnType[\'handle\']>', + ' const GqlOperations = {}', + ' type GqlSdkValues = ReturnType', ...ctx.fns.map(f => fnExp(f, true)), + ` type GqlSdkFuncs = ${ctx.clients.map(c => `ReturnType`).join(' & ')}`, '}' ].join('\n') - ctx.fnImports = ctx.fns.map((fn): Import => ({ - name: fnName(fn), - from: '#build/gql' - })) + ctx.fnImports = ctx.fns.map((fn): Import => ({ from: '#gql', name: fnName(fn) })) } export async function prepareOperations (ctx: GqlContext, path: string[]) { @@ -83,10 +95,8 @@ export async function prepareOperations (ctx: GqlContext, path: string[]) { clientToUse = clientToUse || ctx.clients.find(c => c === 'default') || ctx.clients[0] } - const operationName = op.replace(`${clientToUse}_`, '').replace(op.split('_')[0] + '_', '') - - if (!ctx.clientOps?.[clientToUse]?.includes(operationName)) { - ctx.clientOps[clientToUse].push(operationName) + if (!ctx.clientOps?.[clientToUse]?.includes(op)) { + ctx.clientOps[clientToUse].push(op) } } } @@ -95,40 +105,13 @@ export async function prepareOperations (ctx: GqlContext, path: string[]) { } export function prepareTemplate (ctx: GqlContext) { - const toPSCase = (s: string) => s.split('_').map(upperFirst).join('_') - - const oust = (from: string, to: string) => ctx.template - .replace(new RegExp(from, 'g'), to) - .replace(new RegExp(toPSCase(from), 'g'), toPSCase(to)) - - for (const [client, ops] of Object.entries(ctx.clientOps)) { - if (!ops?.length) { continue } + ctx.clientTypes = ctx.clientTypes || {} - for (const op of ops) { - const originalName = `${client}_${op}` + ctx.clientTypes = Object.entries(ctx.template).reduce((acc, [key, template]) => { + acc[key] = template.match(/^export\stype\s\w+(?=\s=\s)/gm) + .filter(e => !['Scalars', 'SdkFunctionWrapper', 'Sdk'].some(f => e.includes(f))) + .map(e => e.replace('export type ', '')) - const [basic, special] = [op, originalName].map(n => - new RegExp(`\\s${n}\\s*(?=\\(variables)`, 'g').test(ctx.template)) - - if (basic) { continue } - - if (special) { - ctx.template = oust(originalName, op) - - continue - } - - if (!basic && !special) { - const reInvalid = new RegExp(`\\w+_(${op})\\s*(?=\\(variables)`) - - if (!reInvalid.test(ctx.template)) { continue } - - const [invalidName, opName] = reInvalid.exec(ctx.template) - - ctx.template = oust(invalidName, opName) - - continue - } - } - } + return acc + }, {} as Record) } diff --git a/src/generate.ts b/src/generate.ts index b83ae62..3e8ba9b 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -1,24 +1,11 @@ import { generate } from '@graphql-codegen/cli' import type { CodegenConfig } from '@graphql-codegen/cli' -import * as PluginTS from '@graphql-codegen/typescript' -import * as PluginTSOperations from '@graphql-codegen/typescript-operations' -import * as PluginTSGraphqlRequest from '@graphql-codegen/typescript-graphql-request' - -import { defu } from 'defu' -import { $fetch } from 'ohmyfetch' -import { loadSchema } from '@graphql-tools/load' -import { stitchSchemas } from '@graphql-tools/stitch' -import { GraphQLSchema, print, printSchema } from 'graphql' -import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader' -import { wrapSchema, introspectSchema, RenameTypes, RenameRootFields } from '@graphql-tools/wrap' - import type { Resolver } from '@nuxt/kit' -import type { GqlConfig, GqlCodegen, StitchOptions } from './types' +import type { GqlConfig, GqlCodegen } from './types' interface GenerateOptions { clients?: GqlConfig['clients'] - file: string silent?: boolean plugins?: string[] documents?: string[] @@ -26,60 +13,15 @@ interface GenerateOptions { resolver? : Resolver } -function pluginLoader (name: string): Promise { - if (name === '@graphql-codegen/typescript') { return Promise.resolve(PluginTS) } - if (name === '@graphql-codegen/typescript-operations') { return Promise.resolve(PluginTSOperations) } - if (name === '@graphql-codegen/typescript-graphql-request') { return Promise.resolve(PluginTSGraphqlRequest) } -} - -async function prepareSchemas (schemas: Record }>, options?: StitchOptions): Promise { - const generateSchema = async ({ host, headers, ...rest }) => { - const executor = async ({ document, variables }) => await $fetch(host, { - method: 'POST', - headers, - body: JSON.stringify({ query: print(document), variables }) - }) - - return wrapSchema({ ...rest, executor, schema: await introspectSchema(executor) }) - } - - const subschemas: GraphQLSchema[] = [] - - for (const [k, v] of Object.entries(schemas)) { - const host = typeof v === 'string' ? v : v.host - const headers = typeof v === 'string' ? {} : v.headers - - const transforms = [ - ...(options?.prefixTypes ? [new RenameTypes(name => `${k}_${name}`)] : []), - ...(options?.prefixFields ? [new RenameRootFields((_, fieldName) => `${k}_${fieldName}`)] : []) - ] - - let clientSchema: GraphQLSchema = null - - if ((/^(https?:)?\/\//.test(host))) { - clientSchema = await generateSchema({ host, headers, transforms }) - } else { - clientSchema = await loadSchema(v, { loaders: [new GraphQLFileLoader()] }) - .then(schema => wrapSchema({ schema, transforms })).catch(() => null) - - if (!clientSchema) { throw new Error('Unable to load local schema file: ' + v) } - } - - subschemas.push(clientSchema) - } - - return printSchema(stitchSchemas({ subschemas, mergeTypes: options?.mergeTypes })) -} - -async function prepareConfig (options: GenerateOptions & GqlCodegen): Promise { - const schema = Object.entries(options.clients).reduce((acc, [k, v]) => { +function prepareConfig (options: GenerateOptions & GqlCodegen): CodegenConfig { + const prepareSchema = (v: GqlConfig['clients'][number]) => { if (v.schema) { v.schema = options.resolver.resolve(v.schema) - return !options.stitchSchemas && Array.isArray(acc) ? [...acc, v.schema] : { ...acc, [k]: v.schema } + return [v.schema] } if (!v?.token?.value && !v?.headers && !v?.codegenHeaders) { - return !options.stitchSchemas && Array.isArray(acc) ? [...acc, v.host] : { ...acc, [k]: v.host } + return [v.host] } const token = v?.token?.value && `${v?.token?.type} ${v?.token?.value}`.trim() @@ -93,38 +35,55 @@ async function prepareConfig (options: GenerateOptions & GqlCodegen): Promise({}, options.stitchSchemas, { mergeTypes: true }) + const generates: CodegenConfig['generates'] = Object.entries(options.clients).reduce((acc, [k, v]) => { + const clientDocuments = options.documents.filter((file: string) => { + const clientInExt = new RegExp(`\\.${k}\\.(gql|graphql)$`) + const clientInPath = new RegExp(`\\/${k}\\/(?=${file.split('/').pop().replace(/\./g, '\\.')})`) - return { - schema: !options.stitchSchemas ? schema : await prepareSchemas(schema, stitchOptions), - pluginLoader, - silent: options.silent, - documents: options.documents, - generates: { - [options.file]: { + return clientInExt.test(file) || clientInPath.test(file) + }) + + const noClientSpecified = options.documents.filter((file: string) => { + const clientInExt = /\.\w+\.(gql|graphql)$/.test(file) + + const clientInPath = new RegExp(`\\/(${Object.keys(options.clients).join('|')})\\/(?=${file.split('/').pop().replace(/\./g, '\\.')})`).test(file) + + return !clientInExt && !clientInPath + }) + + return { + ...acc, + [`${k}.ts`]: { + config: codegenConfig, + schema: prepareSchema(v), plugins: options.plugins, - config: { - skipTypename: options?.skipTypename, - useTypeImports: options?.useTypeImports, - dedupeFragments: options?.dedupeFragments, - gqlImport: 'graphql-request#gql', - onlyOperationTypes: options.onlyOperationTypes, - namingConvention: { - enumValues: 'change-case-all#upperCaseFirst' - } - } + documents: k !== 'default' ? clientDocuments : noClientSpecified } } - } + }, {}) + + return { silent: options.silent, generates } } -export default async function (options: GenerateOptions): Promise { - const config = await prepareConfig(options) +export default async function (options: GenerateOptions): Promise<{ + filename: string + content: string +}[]> { + const config = prepareConfig(options) - return await generate(config, false).then(([{ content }]) => content) + return await generate(config, false) } diff --git a/src/module.ts b/src/module.ts index 6ff492a..b912618 100644 --- a/src/module.ts +++ b/src/module.ts @@ -39,7 +39,6 @@ export default defineNuxtModule({ const codegenDefaults: GqlCodegen = { silent: true, skipTypename: true, - stitchSchemas: true, useTypeImports: true, dedupeFragments: true, onlyOperationTypes: true @@ -146,41 +145,42 @@ export default defineNuxtModule({ ctx.template = await generate({ clients: config.clients as GqlConfig['clients'], - file: 'gql-sdk.ts', plugins, documents, resolver: srcResolver, ...(typeof config.codegen !== 'boolean' && config.codegen) - }) + }).then(output => output.reduce((acc, c) => ({ ...acc, [c.filename.split('.ts')[0]]: c.content }), {})) await prepareOperations(ctx, documents) - if (Object.keys(config.clients).length > 1 || !config.clients?.default) { - prepareTemplate(ctx) - } + prepareTemplate(ctx) prepareContext(ctx, config.functionPrefix) } - addTemplate({ - write: true, - filename: 'gql-sdk.ts', - getContents: () => ctx.template - }) - addPlugin(resolver.resolve('runtime/plugin')) if (config.autoImport) { + nuxt.options.alias['#gql'] = resolver.resolve(nuxt.options.buildDir, 'gql') + addTemplate({ filename: 'gql.mjs', getContents: () => ctx.generateImports() }) addTemplate({ - filename: 'gql.d.ts', + filename: 'gql/index.d.ts', getContents: () => ctx.generateDeclarations() }) + for (const client of ctx.clients) { + addTemplate({ + write: true, + filename: `gql/${client}.ts`, + getContents: () => ctx.template[client] + }) + } + nuxt.hook('imports:extend', (autoimports) => { autoimports.push(...ctx.fnImports) }) diff --git a/src/runtime/composables/index.ts b/src/runtime/composables/index.ts index cbe7390..c17839b 100644 --- a/src/runtime/composables/index.ts +++ b/src/runtime/composables/index.ts @@ -4,9 +4,9 @@ import type { AsyncData } from 'nuxt/dist/app/composables' import type { GqlState, GqlConfig, GqlError, OnGqlError } from '../../types' import { deepmerge } from '../utils' // @ts-ignore -import { GqlOperations, GqlInstance } from '#build/gql' -import type { GqlClients, GqlFunc } from '#build/gql' -import { getSdk as gqlSdk } from '#build/gql-sdk' +// eslint-disable-next-line import/named +import { GqlSdks, GqlInstance, GqlOperations } from '#gql' +import type { GqlClients, GqlSdkValues, GqlSdkFuncs } from '#gql' import { useState, useNuxtApp, useAsyncData, useRuntimeConfig } from '#imports' const useGqlState = (): Ref => { @@ -99,7 +99,13 @@ export function useGqlHeaders (...args: any[]) { if (respectDefaults && !Object.keys(headers).length) { const defaultHeaders = (useRuntimeConfig()?.public?.['graphql-client'] as GqlConfig)?.clients?.[client || 'default']?.headers - setGqlState({ client, patch: { headers: defaultHeaders } }) + + const serverHeaders = (process.server && (typeof defaultHeaders?.serverOnly === 'object' && defaultHeaders?.serverOnly)) || undefined + if (defaultHeaders?.serverOnly) { delete defaultHeaders.serverOnly } + + headers = { ...(defaultHeaders as Record), ...serverHeaders } + + setGqlState({ client, patch: { headers } }) } } @@ -202,11 +208,11 @@ export const useGql = () => { const state = useGqlState() const errState = useGqlErrorState() - const handle = (client?: GqlClients): ReturnType => { - client = client || 'default' + const handle = (client?: T) => { + client = client || 'default' as T const { instance } = state.value?.[client] - const $gql: ReturnType = gqlSdk(instance, async (action, operationName, operationType): Promise => { + return GqlSdks[client](instance, async (action, operationName, operationType): Promise => { try { return await action() } catch (err) { @@ -224,9 +230,7 @@ export const useGql = () => { throw errState.value } - }) - - return { ...$gql } + }) as GqlSdkValues } return { handle } @@ -268,9 +272,9 @@ const useGqlErrorState = () => useState('_gqlErrors', () => null) * @param {Object} options.options AsyncData options. */ export function useAsyncGql< -T extends keyof GqlFunc, -P extends Parameters['0'], -R extends AsyncData>, GqlError>, +T extends keyof GqlSdkFuncs, +P extends Parameters['0'], +R extends AsyncData>, GqlError>, O extends Parameters['2']> (options: { operation: T, variables?: P, options?: O }): Promise /** @@ -281,9 +285,9 @@ O extends Parameters['2']> (options: { operation: T, variab * @param {Object} options AsyncData options. */ export function useAsyncGql< -T extends keyof GqlFunc, -P extends Parameters['0'], -R extends AsyncData>, GqlError>, +T extends keyof GqlSdkFuncs, +P extends Parameters['0'], +R extends AsyncData>, GqlError>, O extends Parameters['2']> (operation: T, variables?: P, options?: O): Promise export function useAsyncGql (...args: any[]) { diff --git a/src/types.d.ts b/src/types.d.ts index 54fd787..76b5e61 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -86,15 +86,6 @@ export interface GqlCodegen { */ skipTypename?: boolean - /** - * Combine multiple GraphQL APIs into one unified gateway proxy schema that - * knows how to delegate parts of a request to the relevant underlying subschemas. - * - * @type boolean - * @default true - * */ - stitchSchemas?: boolean | StitchOptions - /** * Use `import type {}` rather than `import {}` when importing only types. * diff --git a/test/fixtures/multi-client/nuxt.config.ts b/test/fixtures/multi-client/nuxt.config.ts index badd287..189203f 100644 --- a/test/fixtures/multi-client/nuxt.config.ts +++ b/test/fixtures/multi-client/nuxt.config.ts @@ -8,7 +8,9 @@ export default defineNuxtConfig({ 'graphql-client': { clients: { spacex: 'https://api.spacex.land/graphql', - rmorty: 'https://rickandmortyapi.com/graphql' + rmorty: 'https://rickandmortyapi.com/graphql', + countries: 'https://countries.trevorblades.com/graphql', + todos: 'https://nuxt-gql-server-2gl6xp7kua-ue.a.run.app/query' } } } diff --git a/test/fixtures/multi-client/queries/countries/continents.gql b/test/fixtures/multi-client/queries/countries/continents.gql new file mode 100644 index 0000000..ec66079 --- /dev/null +++ b/test/fixtures/multi-client/queries/countries/continents.gql @@ -0,0 +1,6 @@ +query continents { + continents { + code + name + } +} diff --git a/test/fixtures/multi-client/queries/demo.rmorty.gql b/test/fixtures/multi-client/queries/demo.rmorty.gql new file mode 100644 index 0000000..8f34a89 --- /dev/null +++ b/test/fixtures/multi-client/queries/demo.rmorty.gql @@ -0,0 +1,5 @@ +query character { + character(id: "2") { + name + } +} diff --git a/test/fixtures/multi-client/queries/demo.spacex.gql b/test/fixtures/multi-client/queries/demo.spacex.gql new file mode 100644 index 0000000..ac6c815 --- /dev/null +++ b/test/fixtures/multi-client/queries/demo.spacex.gql @@ -0,0 +1,5 @@ +query launches { + launches(limit: 10) { + id + } +} diff --git a/test/fixtures/multi-client/queries/dual_clients.gql b/test/fixtures/multi-client/queries/dual_clients.gql deleted file mode 100644 index 3604f3b..0000000 --- a/test/fixtures/multi-client/queries/dual_clients.gql +++ /dev/null @@ -1,14 +0,0 @@ -# SpaceX Client -query spacex_launches { - launches(limit: 10) { - id - } -} - - -# Rick and Morty Client -query rmorty_character { - character(id: "2") { - name - } -} diff --git a/test/fixtures/multi-client/queries/rmorty/characters.gql b/test/fixtures/multi-client/queries/rmorty/characters.gql new file mode 100644 index 0000000..eb0bade --- /dev/null +++ b/test/fixtures/multi-client/queries/rmorty/characters.gql @@ -0,0 +1,8 @@ +query getCharacters { + characters { + results { + name + status + } + } +} diff --git a/test/fixtures/multi-client/queries/rmorty/ep.gql b/test/fixtures/multi-client/queries/rmorty/ep.gql index 0b35d88..2235ee6 100644 --- a/test/fixtures/multi-client/queries/rmorty/ep.gql +++ b/test/fixtures/multi-client/queries/rmorty/ep.gql @@ -1,4 +1,4 @@ -query rmorty_first_episode { +query first_episode { episode(id: "1") { name } diff --git a/test/fixtures/multi-client/queries/spacex/demo.gql b/test/fixtures/multi-client/queries/spacex/demo.gql new file mode 100644 index 0000000..01ea23e --- /dev/null +++ b/test/fixtures/multi-client/queries/spacex/demo.gql @@ -0,0 +1,6 @@ +query ships { + ships { + id + name + } +} diff --git a/test/fixtures/multi-client/queries/spacex/mission.gql b/test/fixtures/multi-client/queries/spacex/mission.gql index ef6897e..bbdd2a4 100644 --- a/test/fixtures/multi-client/queries/spacex/mission.gql +++ b/test/fixtures/multi-client/queries/spacex/mission.gql @@ -1,4 +1,4 @@ -query spacex_mission { +query mission { mission(id: "F3364BF") { name } diff --git a/test/fixtures/multi-client/queries/todos/todos.gql b/test/fixtures/multi-client/queries/todos/todos.gql new file mode 100644 index 0000000..b9a6aa5 --- /dev/null +++ b/test/fixtures/multi-client/queries/todos/todos.gql @@ -0,0 +1,6 @@ +query todos { + todos { + id + text + } +}