diff --git a/packages/plugin-graphql/src/core/cache.js b/packages/plugin-graphql/src/core/cache.js index f2ca13ee2..029a99c74 100644 --- a/packages/plugin-graphql/src/core/cache.js +++ b/packages/plugin-graphql/src/core/cache.js @@ -19,8 +19,6 @@ module.exports = async (req, context) => { /* Take the same query from request, and repeat the query for our server side cache */ const { query, variables } = req.body; - // const queryObj = gql`${query}`; - const { data } = await client.query({ query: gql`${query}`, variables @@ -28,8 +26,6 @@ module.exports = async (req, context) => { if (data) { const { outputDir } = context; - - // const cache = JSON.stringify(client.extract()); const cache = JSON.stringify(data); const queryHash = getQueryHash(query, variables); const hashFilename = `${queryHash}-cache.json`; diff --git a/packages/plugin-graphql/src/core/client.js b/packages/plugin-graphql/src/core/client.js index 787ed9cef..b968ce87d 100644 --- a/packages/plugin-graphql/src/core/client.js +++ b/packages/plugin-graphql/src/core/client.js @@ -40,40 +40,4 @@ client.query = (params) => { } }; -export default client; - -// import { ApolloClient } from 'apollo-client'; -// import { InMemoryCache } from 'apollo-cache-inmemory'; -// import { HttpLink } from 'apollo-link-http'; -// import { getQueryHash } from '@greenwood/cli/data/common'; - -// const APOLLO_STATE = window.__APOLLO_STATE__; // eslint-disable-line no-underscore-dangle -// const client = new ApolloClient({ -// cache: new InMemoryCache(), -// link: new HttpLink({ -// uri: 'http://localhost:4000' -// }) -// }); -// const backupQuery = client.query; - -// client.query = (params) => { -// if (APOLLO_STATE) { -// __APOLLO_STATE__ defined, in production mode -// const queryHash = getQueryHash(params.query, params.variables); -// const cachePath = `/${queryHash}-cache.json`; - -// return fetch(cachePath) -// .then(response => response.json()) -// .then((response) => { -// // mock client.query response -// return { -// data: new InMemoryCache().restore(response).readQuery(params) -// }; -// }); -// } else { -// // __APOLLO_STATE__ NOT defined, in development mode -// return backupQuery(params); -// } -// }; - -// export default client; \ No newline at end of file +export default client; \ No newline at end of file diff --git a/packages/plugin-graphql/src/core/common.client.js b/packages/plugin-graphql/src/core/common.client.js index bc3d95f44..aa46cb316 100644 --- a/packages/plugin-graphql/src/core/common.client.js +++ b/packages/plugin-graphql/src/core/common.client.js @@ -9,31 +9,8 @@ function hashString(queryKeysString) { return Math.abs(h).toString(); } -// function getQueryKeysFromSelectionSet(selectionSet) { -// let queryKeys = ''; - -// for (let key in selectionSet) { - -// if (key === 'selections') { -// queryKeys += selectionSet[key] -// .filter(selection => selection.name.value !== '__typename') // __typename is added by server.js -// .map(selection => selection.name.value).join(''); -// } -// } - -// if (selectionSet.kind === 'SelectionSet') { -// selectionSet.selections.forEach(selection => { -// if (selection.selectionSet) { -// queryKeys += getQueryKeysFromSelectionSet(selection.selectionSet); -// } -// }); -// } - -// return queryKeys; -// } - function getQueryHash(query, variables = {}) { - const queryKeys = query; // getQueryKeysFromSelectionSet(query.definitions[0].selectionSet); + const queryKeys = query; const variableValues = Object.keys(variables).length > 0 ? `_${Object.values(variables).join('').replace(/\//g, '')}` // handle / which will translate to filepaths : ''; diff --git a/packages/plugin-graphql/src/core/common.server.js b/packages/plugin-graphql/src/core/common.server.js index 565f01162..85026762e 100644 --- a/packages/plugin-graphql/src/core/common.server.js +++ b/packages/plugin-graphql/src/core/common.server.js @@ -9,31 +9,8 @@ function hashString(queryKeysString) { return Math.abs(h).toString(); } -// function getQueryKeysFromSelectionSet(selectionSet) { -// let queryKeys = ''; - -// for (let key in selectionSet) { - -// if (key === 'selections') { -// queryKeys += selectionSet[key] -// .filter(selection => selection.name.value !== '__typename') // __typename is added by server.js -// .map(selection => selection.name.value).join(''); -// } -// } - -// if (selectionSet.kind === 'SelectionSet') { -// selectionSet.selections.forEach(selection => { -// if (selection.selectionSet) { -// queryKeys += getQueryKeysFromSelectionSet(selection.selectionSet); -// } -// }); -// } - -// return queryKeys; -// } - function getQueryHash(query, variables = {}) { - const queryKeys = query; // getQueryKeysFromSelectionSet(query.definitions[0].selectionSet); + const queryKeys = query; const variableValues = Object.keys(variables).length > 0 ? `_${Object.values(variables).join('').replace(/\//g, '')}` // handle / which will translate to filepaths : ''; diff --git a/packages/plugin-graphql/src/index.js b/packages/plugin-graphql/src/index.js index f74982cf4..fd93d0955 100644 --- a/packages/plugin-graphql/src/index.js +++ b/packages/plugin-graphql/src/index.js @@ -1,6 +1,5 @@ const fs = require('fs'); const graphqlServer = require('./core/server'); -// const gql = require('graphql-tag'); const path = require('path'); const { ResourceInterface } = require('@greenwood/cli/src/lib/resource-interface'); const { ServerInterface } = require('@greenwood/cli/src/lib/server-interface'); @@ -17,10 +16,6 @@ class GraphQLResource extends ResourceInterface { return new Promise(async (resolve, reject) => { try { const js = await fs.promises.readFile(url, 'utf-8'); - // const gqlJs = gql`${js}`; - // const body = ` - // export default ${JSON.stringify(gqlJs)}; - // `; const body = ` export default \`${js}\`; `; @@ -39,27 +34,6 @@ class GraphQLResource extends ResourceInterface { return Promise.resolve(headers.request.accept && headers.request.accept.indexOf('text/html') >= 0); } - // "apollo-client": "/node_modules/apollo-client/bundle.esm.js", - // "apollo-cache-inmemory": "/node_modules/apollo-cache-inmemory/lib/bundle.esm.js", - // "apollo-link-http": "/node_modules/apollo-link-http/lib/bundle.esm.js", - // "apollo-utilities": "/node_modules/apollo-utilities/lib/bundle.esm.js", - // "apollo-link": "/node_modules/apollo-link/lib/bundle.esm.js", - // "apollo-cache": "/node_modules/apollo-cache/lib/bundle.esm.js", - // "apollo-link-http-common": "/node_modules/apollo-link-http-common/lib/bundle.esm.js", - // "optimism": "/node_modules/optimism/lib/bundle.esm.js", - // "tslib": "/node_modules/tslib/tslib.es6.js", - // "symbol-observable": "/node_modules/symbol-observable/es/index.js", - // "ts-invariant": "/node_modules/ts-invariant/lib/invariant.esm.js", - // "@wry/context": "/node_modules/@wry/context/lib/context.esm.js", - // "@wry/equality": "/node_modules/@wry/equality/lib/equality.esm.js", - // "graphql/jsutils/inspect": "/node_modules/graphql/jsutils/inspect.mjs", - // "graphql/language/visitor": "/node_modules/graphql/language/visitor.mjs", - // "graphql/language/parser": "/node_modules/graphql/language/parser.mjs", - // "graphql/language/printer": "/node_modules/graphql/language/printer.mjs", - // "zen-observable": "/node_modules/zen-observable/esm.js", - // "zen-observable-ts": "/node_modules/zen-observable-ts/lib/bundle.esm.js", - // "fast-json-stable-stringify": "/node_modules/fast-json-stable-stringify/index.js", - // "graphql-tag": "/node_modules/graphql-tag/src/index.js", async intercept(url, body) { return new Promise(async (resolve, reject) => { try {