graphql-genie
Advanced tools
Comparing version 0.4.14 to 0.4.15
import { GraphQLNonNull, getNamedType, isInputObjectType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isSpecifiedDirective, isUnionType, print } from 'graphql'; | ||
import { GraphQLDate, GraphQLDateTime, GraphQLTime } from 'graphql-iso-date'; | ||
import { SchemaDirectiveVisitor, addResolveFunctionsToSchema, makeExecutableSchema } from 'graphql-tools'; | ||
import { SchemaDirectiveVisitor, addResolveFunctionsToSchema, buildSchemaFromTypeDefinitions, makeExecutableSchema } from 'graphql-tools'; | ||
import GraphQLJSON from 'graphql-type-json'; | ||
import { camelCase, find, has, isEmpty, set, values } from 'lodash'; | ||
import { camelCase, each, find, has, isEmpty, set, values } from 'lodash'; | ||
import pluralize from 'pluralize'; | ||
@@ -64,2 +64,52 @@ import { getReturnType, typeIsList } from './GraphQLUtils'; | ||
} | ||
// let's make sure we have a valid schema | ||
try { | ||
buildSchemaFromTypeDefinitions(newTypeDefs); | ||
} | ||
catch (e) { | ||
// let's see if it errored due to unknown directive, which is something we can fake past and assume the directive will be added later | ||
let match; | ||
let hasMatch = false; | ||
const re = /Unknown directive\s*"(.*)"/g; | ||
let directiveTypeDefs = newTypeDefs; | ||
while ((match = re.exec(e.message)) != null) { | ||
hasMatch = true; | ||
if (match[1] && !directiveTypeDefs.includes(`directive @${match[1]}`)) { | ||
directiveTypeDefs += ` | ||
directive @${match[1]} on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
`; | ||
} | ||
} | ||
if (hasMatch) { | ||
try { | ||
buildSchemaFromTypeDefinitions(directiveTypeDefs); | ||
newTypeDefs = directiveTypeDefs; | ||
} | ||
catch (e) { | ||
// we added the directive but still error, let's add the arguments | ||
hasMatch = false; | ||
const re = /Unknown argument\s*"(.*)"\s*on directive\s*"@(.*)"/g; | ||
const directives = {}; | ||
while ((match = re.exec(e.message)) != null) { | ||
hasMatch = true; | ||
directives[match[2]] = directives[match[2]] ? directives[match[2]] : []; | ||
const field = match[1] + ': JSON'; | ||
if (!directives[match[2]].includes(field)) { | ||
directives[match[2]].push(field); | ||
} | ||
} | ||
if (hasMatch) { | ||
directiveTypeDefs = newTypeDefs; | ||
each(directives, (fields, directive) => { | ||
directiveTypeDefs += ` | ||
directive @${directive} ( | ||
${fields.join('\n')} | ||
) on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
`; | ||
}); | ||
newTypeDefs = directiveTypeDefs; | ||
} | ||
} | ||
} | ||
} | ||
this.schema = makeExecutableSchema({ | ||
@@ -140,5 +190,5 @@ typeDefs: newTypeDefs, | ||
else { // if an object type grab from existing query type | ||
let queryFieldName = `${camelCase(pluralize(returnType.name))}`; | ||
let queryFieldName = `${camelCase(pluralize(returnType.name))} `; | ||
if (returnType.name.endsWith('Connection')) { | ||
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))}Connection`; | ||
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))} Connection`; | ||
} | ||
@@ -145,0 +195,0 @@ const queryField = queryTypeFields[queryFieldName]; |
{ | ||
"name": "graphql-genie", | ||
"version": "0.4.14", | ||
"version": "0.4.15", | ||
"description": "GraphQL Genie", | ||
@@ -41,3 +41,3 @@ "browser": "./lib/browser.umd.js", | ||
"lint": "tslint -c tslint.json -p linttsconfig.json --fix", | ||
"lint-no-fix": "tslint -c tslint.json -p linttsconfig.json", | ||
"lint-no-fix": "tslint -c tslint.json -p linttsconfig.json", | ||
"tag": "git tag -a v`npm v graphql-genie version` && git push origin --tags" | ||
@@ -71,3 +71,3 @@ }, | ||
"fortune": "^5.4.2", | ||
"graphql": "^0.13.2", | ||
"graphql": "^14.0.0", | ||
"graphql-fields": "^1.1.0", | ||
@@ -74,0 +74,0 @@ "graphql-genie": "^0.4.0", |
import { DocumentNode, GraphQLFieldResolver, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLType, getNamedType, isInputObjectType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isSpecifiedDirective, isUnionType, print } from 'graphql'; | ||
import { DocumentNode, GraphQLFieldResolver, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLType, getNamedType, isInputObjectType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isSpecifiedDirective, isUnionType, print } from 'graphql'; | ||
import { GraphQLDate, GraphQLDateTime, GraphQLTime } from 'graphql-iso-date'; | ||
import { IResolvers, SchemaDirectiveVisitor, addResolveFunctionsToSchema, makeExecutableSchema } from 'graphql-tools'; | ||
import { IResolvers, SchemaDirectiveVisitor, addResolveFunctionsToSchema, buildSchemaFromTypeDefinitions, makeExecutableSchema } from 'graphql-tools'; | ||
import GraphQLJSON from 'graphql-type-json'; | ||
import { camelCase, find, has, isEmpty, set, values } from 'lodash'; | ||
import { camelCase, each, find, has, isEmpty, set, values } from 'lodash'; | ||
import pluralize from 'pluralize'; | ||
import { GenerateConfig } from './GraphQLGenieInterfaces'; | ||
import { GenerateConfig, GenericObject } from './GraphQLGenieInterfaces'; | ||
import { getReturnType, typeIsList } from './GraphQLUtils'; | ||
@@ -121,3 +121,50 @@ import { getRootMatchFields, queryArgs } from './TypeGeneratorUtilities'; | ||
} | ||
// let's make sure we have a valid schema | ||
try { | ||
buildSchemaFromTypeDefinitions(newTypeDefs); | ||
} catch (e) { | ||
// let's see if it errored due to unknown directive, which is something we can fake past and assume the directive will be added later | ||
let match; | ||
let hasMatch = false; | ||
const re = /Unknown directive\s*"(.*)"/g; | ||
let directiveTypeDefs = newTypeDefs; | ||
while ((match = re.exec(e.message)) != null) { | ||
hasMatch = true; | ||
if (match[1] && !directiveTypeDefs.includes(`directive @${match[1]}`)) { | ||
directiveTypeDefs += ` | ||
directive @${match[1]} on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
`; | ||
} | ||
} | ||
if (hasMatch) { | ||
try { | ||
buildSchemaFromTypeDefinitions(directiveTypeDefs); | ||
newTypeDefs = directiveTypeDefs; | ||
} catch (e) { | ||
// we added the directive but still error, let's add the arguments | ||
hasMatch = false; | ||
const re = /Unknown argument\s*"(.*)"\s*on directive\s*"@(.*)"/g; | ||
const directives: GenericObject = {}; | ||
while ((match = re.exec(e.message)) != null) { | ||
hasMatch = true; | ||
directives[match[2]] = directives[match[2]] ? directives[match[2]] : []; | ||
const field = match[1] + ': JSON'; | ||
if (!directives[match[2]].includes(field)) { | ||
directives[match[2]].push(field); | ||
} | ||
} | ||
if (hasMatch) { | ||
directiveTypeDefs = newTypeDefs; | ||
each(directives, (fields, directive) => { | ||
directiveTypeDefs += ` | ||
directive @${directive} ( | ||
${fields.join('\n')} | ||
) on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ||
`; | ||
}); | ||
newTypeDefs = directiveTypeDefs; | ||
} | ||
} | ||
} | ||
} | ||
this.schema = makeExecutableSchema({ | ||
@@ -200,5 +247,5 @@ typeDefs: newTypeDefs, | ||
} else { // if an object type grab from existing query type | ||
let queryFieldName = `${camelCase(pluralize(returnType.name))}`; | ||
let queryFieldName = `${camelCase(pluralize(returnType.name))} `; | ||
if (returnType.name.endsWith('Connection')) { | ||
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))}Connection`; | ||
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))} Connection`; | ||
} | ||
@@ -205,0 +252,0 @@ const queryField = queryTypeFields[queryFieldName]; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1085562
23030