Comparing version 0.4.3 to 0.4.4
28
index.js
@@ -20,8 +20,9 @@ #!/usr/bin/env node | ||
program | ||
.version('0.3.0') | ||
.version('0.4.4') | ||
.usage('[options] <schema.json>') | ||
.option('-e --export', 'use export rather than declare to define types') | ||
.option( | ||
'-o --output-file [outputFile]', | ||
'name for ouput file, defaults to graphql-export.flow.js', | ||
'graphql-export.flow.js' | ||
'graphql-export.flow.js', | ||
) | ||
@@ -33,9 +34,24 @@ .option('--null-keys [nullKeys]', 'makes all keys nullable', false) | ||
'name for the export module. Types are not wrapped in a module if this is not set', | ||
'' | ||
'', | ||
) | ||
.option( | ||
'-t --typeMap <typeSpec>', | ||
'Define custom scalar types where typeSpec is <graphql type>:<flow type>', | ||
(val, typeMap) => { | ||
const [graphqlType, flowType] = val.split(':'); | ||
if (!graphqlType || !flowType) { | ||
throw new Error( | ||
'-t argument format should be <graphql type>:<flow type>', | ||
); | ||
} | ||
typeMap[graphqlType] = flowType; | ||
return typeMap; | ||
}, | ||
{}, | ||
) | ||
.option( | ||
'-i --ignored-types <ignoredTypes>', | ||
'names of types to ignore (comma delimited)', | ||
v => v.split(','), | ||
[] | ||
[], | ||
) | ||
@@ -46,3 +62,3 @@ .option( | ||
v => v.split(','), | ||
[] | ||
[], | ||
) | ||
@@ -57,3 +73,3 @@ .action((path, options) => { | ||
reject( | ||
new Error('Server replied with an invalid introspection schema') | ||
new Error('Server replied with an invalid introspection schema'), | ||
); | ||
@@ -60,0 +76,0 @@ } else { |
{ | ||
"name": "gql2flow", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Convert a GraphQL Schema to a Flowtype definition", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const generateTypes = (schema, options) => { | ||
const exportOrDeclare = options.moduleName ? 'export' : 'declare'; | ||
const exportOrDeclare = (options.export || options.moduleName) ? 'export' : 'declare'; | ||
@@ -28,3 +28,3 @@ const generateRootDataName = schema => { | ||
${exportOrDeclare} type GraphQLResponseError = { | ||
${exportOrDeclare} type GraphQLResponseError = { | ||
message: string; // Required for all errors | ||
@@ -35,5 +35,5 @@ locations?: Array<GraphQLResponseErrorLocation>; | ||
${exportOrDeclare} type GraphQLResponseErrorLocation = { | ||
line: number; | ||
column: number; | ||
${exportOrDeclare} type GraphQLResponseErrorLocation = { | ||
line: number; | ||
column: number; | ||
}`; | ||
@@ -55,7 +55,6 @@ | ||
fields, | ||
additionalInfo, | ||
isInput | ||
additionalInfo | ||
) => | ||
`${additionalInfo}${generateDescription(description)}${exportOrDeclare} type ${declaration} = { | ||
${isInput ? '' : fields} | ||
${fields} | ||
}`; | ||
@@ -91,3 +90,3 @@ | ||
default: | ||
return 'any'; | ||
return options.typeMap[type.name] || 'any'; | ||
} | ||
@@ -106,3 +105,3 @@ | ||
const fieldToDefinition = (field, isInput) => { | ||
const fieldToDefinition = (field) => { | ||
let interfaceName = resolveInterfaceName(field.type); | ||
@@ -154,3 +153,3 @@ let isNotNull = field.type.kind === 'NON_NULL'; | ||
.filter(field => filterField(field, ignoredTypes)) | ||
.map(field => fieldToDefinition(field, isInput)) | ||
.map(field => fieldToDefinition(field)) | ||
.filter(field => field) | ||
@@ -180,4 +179,3 @@ .join('\n'); | ||
fields, | ||
additionalInfo, | ||
isInput | ||
additionalInfo | ||
); | ||
@@ -184,0 +182,0 @@ }; |
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
12492
326