Skip to content

Commit

Permalink
delete commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Mar 19, 2021
1 parent f54d64f commit 11acd31
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 115 deletions.
4 changes: 0 additions & 4 deletions packages/plugin-graphql/src/core/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ 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
});

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`;
Expand Down
38 changes: 1 addition & 37 deletions packages/plugin-graphql/src/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
export default client;
25 changes: 1 addition & 24 deletions packages/plugin-graphql/src/core/common.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
: '';
Expand Down
25 changes: 1 addition & 24 deletions packages/plugin-graphql/src/core/common.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
: '';
Expand Down
26 changes: 0 additions & 26 deletions packages/plugin-graphql/src/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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}\`;
`;
Expand All @@ -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 {
Expand Down

0 comments on commit 11acd31

Please sign in to comment.