Skip to content

Upgrade Graphql-js version #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-faker",
"version": "1.7.6",
"version": "1.7.6-damian0",
"description": "Mock or extend your GraphQL API with faked data. No coding required",
"main": "dist/index.js",
"bin": "dist/index.js",
Expand All @@ -11,7 +11,7 @@
"build:editor": "cd src/editor && yarn && npm run build && cd -",
"build:typescript": "tsc",
"copy:graphql": "cp src/*.graphql dist/",
"copy:editor": "mkdir -p dist/editor && cp src/editor/*.{html,js,css,svg} dist/editor",
"copy:editor": "mkdir -p dist/editor && bash -c \" cp src/editor/*.{html,js,css,svg} dist/editor\"",
"build:all": "npm run build:editor && npm run build:typescript && npm run copy:graphql && npm run copy:editor"
},
"repository": {
Expand All @@ -30,12 +30,12 @@
"@types/express": "4.16.0",
"@types/express-graphql": "0.6.1",
"@types/faker": "4.1.3",
"@types/graphql": "0.11.4",
"@types/graphql": "14.0.0",
"@types/lodash": "4.14.116",
"@types/yargs": "11.1.1",
"nodemon": "1.18.3",
"nodemon": "1.18.4",
"ts-node": "7.0.1",
"typescript": "3.0.1"
"typescript": "3.0.3"
},
"dependencies": {
"body-parser": "1.18.3",
Expand All @@ -45,11 +45,12 @@
"express": "4.16.3",
"express-graphql": "github:apis-guru/express-graphql#rootValue_dist",
"faker": "4.1.0",
"graphql": "github:apis-guru/graphql-js#directives-fork-dist",
"lodash": "4.17.10",
"graphql": "*",
"lodash": "4.17.11",
"moment": "2.22.2",
"node-fetch": "2.2.0",
"opn": "5.3.0",
"yargs": "12.0.1"
"updates": "^4.3.0",
"yargs": "12.0.2"
}
}
4 changes: 3 additions & 1 deletion src/editor/GraphQLEditor/GraphQLEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export default class GraphQLEditor extends React.Component<GraphQLEditorProps> {
foldGutter: {
minFoldSize: 4,
},
/*
lint: {
schema,
},
*/
hintOptions: {
schema,
closeOnUnfocus: false,
Expand Down Expand Up @@ -122,7 +124,7 @@ export default class GraphQLEditor extends React.Component<GraphQLEditorProps> {
const { value, schema } = this.props;

if (schema != prevProps.schema) {
this.editor.options.lint.schema = schema;
//this.editor.options.lint.schema = schema;
this.editor.options.hintOptions.schema = schema;
this.editor.options.info.schema = schema;
this.editor.options.jump.schema = schema;
Expand Down
33 changes: 27 additions & 6 deletions src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'graphiql/graphiql.css';

import * as classNames from 'classnames';
import * as GraphiQL from 'graphiql';
import { buildSchema, extendSchema, GraphQLSchema, parse } from 'graphql';
import { buildSchema, extendSchema, GraphQLSchema, parse} from 'graphql';
import * as fetch from 'isomorphic-fetch';
import * as fakeIDL from 'raw-loader!../fake_definition.graphql';
import * as React from 'react';
Expand Down Expand Up @@ -88,22 +88,42 @@ class FakeEditor extends React.Component<any, FakeEditorState> {
return this.fetcher('/user-idl', {
method: 'post',
headers: { 'Content-Type': 'text/plain' },
body: idl,
body: idl

});
}

buildSchema(value) {
var concatFake = true;
var concat='';
//Check if extend another fake schema to avoid add the fakeIDL
if (value.includes("fake__Locale")){
concatFake=false;
}
if (this.state.proxiedSchemaIDL) {
let schema = buildSchema(this.state.proxiedSchemaIDL + '\n' + fakeIDL);
if (concatFake && this.state.proxiedSchemaIDL.includes("fake__Locale")){
concatFake=false;
}
concat = this.state.proxiedSchemaIDL;
if (concatFake){
concat += '\n' + fakeIDL;
}
let schema = buildSchema(concat);
return extendSchema(schema, parse(value));

} else {
return buildSchema(value + '\n' + fakeIDL);
concat = value;
if (concatFake){
concat += '\n' + fakeIDL;
}
return buildSchema(concat);
}
}

updateIdl(value, noError = false) {
try {
const schema = this.buildSchema(value);

this.setState(prevState => ({
...prevState,
schema,
Expand All @@ -130,7 +150,6 @@ class FakeEditor extends React.Component<any, FakeEditorState> {
if (!dirty) return;

if (!this.updateIdl(value)) return;

this.postIDL(value).then(res => {
if (res.ok) {
this.setStatus('Saved!', 2000);
Expand Down Expand Up @@ -161,7 +180,9 @@ class FakeEditor extends React.Component<any, FakeEditorState> {
let dirtySchema = null as GraphQLSchema | null;
try {
dirtySchema = this.buildSchema(val);
} catch(_) { }
} catch(_) {

}

this.setState(prevState => ({
...prevState,
Expand Down
8 changes: 4 additions & 4 deletions src/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"dependencies": {
"classnames": "^2.2.5",
"codemirror": "5.23.0",
"codemirror-graphql": "github:apis-guru/codemirror-graphql#directives-fork-dist",
"graphiql": "^0.9.3",
"graphql": "^0.9.0",
"codemirror": "^5.40.0",
"codemirror-graphql": "^0.6.12",
"graphiql": "*",
"graphql": "^14.0.2",
"isomorphic-fetch": "^2.2.1",
"marked": "^0.3.6",
"react": "^15.4.2",
Expand Down
24 changes: 14 additions & 10 deletions src/editor/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1211,21 +1211,21 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

codemirror-graphql@^0.6.3:
codemirror-graphql@^0.6.12, codemirror-graphql@^0.6.3:
version "0.6.12"
resolved "https://registry.yarnpkg.com/codemirror-graphql/-/codemirror-graphql-0.6.12.tgz#91a273fe5188857524a30221d06e645b4ca41f00"
dependencies:
graphql-language-service-interface "^1.0.16"
graphql-language-service-parser "^0.1.14"

"codemirror-graphql@github:apis-guru/codemirror-graphql#directives-fork-dist":
version "0.6.3"
resolved "https://codeload.github.com/apis-guru/codemirror-graphql/tar.gz/518625d1d5229cffe1fceba62258683a03d62854"

[email protected]:
version "5.23.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.23.0.tgz#ac9b6b2e163a79e915b44cf0f43cd115cf6982dc"

codemirror@^5.40.0:
version "5.40.0"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.40.0.tgz#2f5ed47366e514f41349ba0fe34daaa39be4e257"

collection-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
Expand Down Expand Up @@ -2475,11 +2475,11 @@ graphql@^0.12.3:
dependencies:
iterall "1.1.3"

graphql@^0.9.0:
version "0.9.6"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.9.6.tgz#514421e9d225c29dfc8fd305459abae58815ef2c"
graphql@^14.0.2:
version "14.0.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.0.2.tgz#7dded337a4c3fd2d075692323384034b357f5650"
dependencies:
iterall "^1.0.0"
iterall "^1.2.2"

handle-thing@^1.2.5:
version "1.2.5"
Expand Down Expand Up @@ -3035,10 +3035,14 @@ isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"

[email protected], iterall@^1.0.0:
[email protected]:
version "1.1.3"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9"

iterall@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"

js-base64@^2.1.9:
version "2.4.0"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.0.tgz#9e566fee624751a1d720c966cd6226d29d4025aa"
Expand Down
2 changes: 1 addition & 1 deletion src/fake_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function fakeSchema(schema: GraphQLSchema) {

function abstractTypeResolver(type:GraphQLAbstractType) {
const possibleTypes = schema.getPossibleTypes(type);
return () => ({__typename: getRandomItem(possibleTypes)});
return () => ({__typename: getRandomItem(possibleTypes as Array<GraphQLObjectType>)});
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,29 @@ if (argv.e) {
});
}

function buildServerSchema(idl) {
var ast = concatAST([parse(idl), fakeDefinitionAST]);
function buildServerSchema(idl, concatFake=true) {
var ast =parse(idl);
if (concatFake){
var ast = concatAST([parse(idl), fakeDefinitionAST]);
}
return buildASTSchema(ast);
}

function runServer(schemaIDL: Source, extensionIDL: Source, optionsCB) {
const app = express();

//Check if extend another fake schema to avoid add the fakeIDL
var concatAST=true;
if (schemaIDL.body.includes("fake__Locale")){
concatAST=false;
}
if (extensionIDL) {
const schema = buildServerSchema(schemaIDL);
const schema = buildServerSchema(schemaIDL, concatAST);
extensionIDL.body = extensionIDL.body.replace('<RootTypeName>', schema.getQueryType().name);
}
app.options('/graphql', cors(corsOptions))
app.use('/graphql', cors(corsOptions), graphqlHTTP(req => {
const schema = buildServerSchema(schemaIDL);

const schema = buildServerSchema(schemaIDL, concatAST);
const forwardHeaders = pick(req.headers, forwardHeaderNames);
return {
...optionsCB(schema, extensionIDL, forwardHeaders),
Expand Down
25 changes: 19 additions & 6 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ export function proxyMiddleware(url, headers) {
return getIntrospection().then(introspection => {
const introspectionSchema = buildClientSchema(introspection.data);
const introspectionIDL = printSchema(introspectionSchema);

return [introspectionIDL, (serverSchema, extensionIDL, forwardHeaders) => {
const extensionAST = parse(extensionIDL);

const extensionFields = getExtensionFields(extensionAST);

const schema = extendSchema(serverSchema, extensionAST);


fakeSchema(schema);

//TODO: proxy extensions
Expand Down Expand Up @@ -104,12 +107,22 @@ function buildRootValue(response) {

function getExtensionFields(extensionAST) {
const extensionFields = {};
(extensionAST.definitions || []).forEach(def => {
if (def.kind !== Kind.TYPE_EXTENSION_DEFINITION)
return;
const typeName = def.definition.name.value;
extensionAST.definitions.forEach(def => {
var extensionsDefintions = [
Kind.SCALAR_TYPE_EXTENSION,
Kind.SCHEMA_EXTENSION,
Kind.OPERATION_TYPE_DEFINITION,
Kind.ENUM_TYPE_EXTENSION,
Kind.INPUT_OBJECT_TYPE_EXTENSION,
Kind.INTERFACE_TYPE_EXTENSION,
Kind.OBJECT_TYPE_EXTENSION,
Kind.UNION_TYPE_EXTENSION
]
if (extensionsDefintions.includes(def.kind)){
const typeName = def.name.value;
// FIXME: handle multiple extends of the same type
extensionFields[typeName] = def.definition.fields.map(field => field.name.value);
extensionFields[typeName] = def.fields.map(field => field.name.value);
}
});
return extensionFields;
}
Expand Down