-
Notifications
You must be signed in to change notification settings - Fork 4
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
Am I right to assume the language flow package is an incomplete work in progress. #78
Comments
It should work fine. It was more of an example of how to extend this to generate outputs for other languages. Does it not work? I believe there are only minor differences between flow and ts, which I think were accounted for |
I'm using flow and having some issues. First of all, there is no CLI options for using flow (from what I could tell). So I used the from-schema package. generateNamespace is the documented way to do it, and flow does not support namespaces. Another issue I'm having are duplicated type names, which is because I want a graphql type to exported as a type, not as an interface. More on that in #103 Here's how im using the lib: const { generateNamespace } = require('@gql2ts/from-schema')
const schemaDoc = require('./src/graphql/typeDefs')
const { DEFAULT_OPTIONS: flowDefaults } = require('@gql2ts/language-flow')
const fs = require('fs')
const myNamespace = generateNamespace('Humanise', schemaDoc, { ingnoreTypeNameDeclaration: true }, {
...flowDefaults,
interfaceBuilder: (name, body) => `export type ${name} = ${body}`,
typeBuilder: (name, body) => `export type ${name} = ${body}`,
generateNamespace: (namespaceName, interfaces) => interfaces,
generateInterfaceName: (name) => `${name}`
})
fs.writeFileSync('flowtypes.js', myNamespace) |
@jwickens I'm not using flow but if you could set me up with a starter repo, I'd be glad to help through the issues you've encountered |
@jwickens you should be able use the -e flag with |
added to #163 |
flow
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ server/generated/types.flow.js:6:9
Unexpected identifier
3│ // tslint:disable
4│ // graphql typescript definitions
5│
6│ declare namespace GQL {
7│ interface IGraphQLResponseRoot {
8│ data?: IQuery;
9│ errors?: Array<IGraphQLResponseError>;
Found 1 error
|
@linonetwo I'm not super familiar with how flow declares this. for what it's worth you can overwrite the |
Seems @arahansen is making a working version in his PR, I'm using his version locally waiting his PR to be merged https://github.com/arahansen/gql2ts/blob/fa648647c642b2bac1ee8c7e14f62288807101ff/packages/language-flow/src/index.ts |
But @arahansen 's version still ends each line with gql2ts ./server/generated/schema.json -e $PWD/scripts/@gql2ts-language-flow.js -o ./server/generated/types.flow.js && prettier-eslint \"./server/generated/*.js\" --write |
@linonetwo if prettier is installed, it should run the output through it by default. i'm not sure what you mean about the semicolons, can you give an example? is that in an type/interface declaration? |
It looks like this without export type Block = {
blockNum: number;
blockID: string;
prevBlockID: ?string;
timestamp: string;
transactionMerkleRoot: string;
producerAccountID: string;
pending: boolean;
transactions: Array<Transaction>;
} After formatting: export type Block = {
blockNum: number,
blockID: string,
prevBlockID: ?string,
timestamp: string,
transactionMerkleRoot: string,
producerAccountID: string,
pending: boolean,
transactions: Array<Transaction>,
}; So my scripts includes {
"gql2flow": "yarn build-schema && yarn gql-gen && yarn gqlJson2flow",
"build-schema": "mkdir -p ./server/generated && node ./scripts/buildSchema.js > ./server/generated/schema.graphql",
"gql-gen": "apollo-codegen introspect-schema ./server/generated/schema.graphql --output ./server/generated/schema.json",
"gqlJson2flow": "gql2ts ./server/generated/schema.json -e $PWD/scripts/@gql2ts-language-flow.js -o ./server/generated/types.flow.js --ignore-type-name-declaration && prettier-eslint \"./server/generated/*.js\" --write"
} and // buildSchema.js
const { importSchema } = require('graphql-import');
console.log(importSchema('./server/graphql/schema.graphql')); |
@linonetwo Enums are included in the output with your script. Here is a fix for enums: import {
IFromQueryOptions,
WrapType,
InterfaceAndTypeBuilder,
TypePrinter,
NamespaceGenerator,
} from '@gql2ts/types'
import {DEFAULT_OPTIONS as TS_OPTIONS} from '@gql2ts/language-typescript'
import {pascalize} from 'humps'
import * as util from '@gql2ts/util'
export const FLOW_WRAP_PARTIAL: WrapType = partial => `$SHAPE<${partial}>`
export const FLOW_INTERFACE_NAMER: WrapType = name => `${pascalize(name)}`
export const FLOW_INTERFACE_BUILDER: InterfaceAndTypeBuilder = (name, body) =>
`export type ${name} = ${body}`
export const FLOW_ENUM_NAME_GENERATOR: WrapType = name => `${pascalize(name)}`
export const FLOW_TYPE_PRINTER: TypePrinter = (type, isNonNull) =>
isNonNull ? type : `?${type}`
export const FLOW_POST_PROCESSOR: WrapType = str => `/* @flow */
${str}
`
export const FLOW_NAMESPACE_GENERATOR: NamespaceGenerator = (_, interfaces) => `
// graphql flow definitions
${interfaces}
`
export const DEFAULT_OPTIONS: IFromQueryOptions = {
...TS_OPTIONS,
printType: FLOW_TYPE_PRINTER,
generateInterfaceName: FLOW_INTERFACE_NAMER,
generateEnumName: FLOW_ENUM_NAME_GENERATOR,
enumTypeBuilder: (name, values) => `type ${name} = ${values}`,
formatEnum: (values, documentationGenerator) => `
${util.filterAndJoinArray(
values.map(value =>
util.filterAndJoinArray([
documentationGenerator(util.buildDocumentation(value)),
`'${value.name}'`,
]),
),
' |\n',
)}
`,
interfaceBuilder: FLOW_INTERFACE_BUILDER,
generateNamespace: FLOW_NAMESPACE_GENERATOR,
wrapPartial: FLOW_WRAP_PARTIAL,
postProcessor: FLOW_POST_PROCESSOR,
}
export default DEFAULT_OPTIONS |
Also @linonetwo, you don't need to do this:
gql2ts can work with |
I wanted to have flow as a target language but saw not tests or examples hence my assumption that its a work in progress. If its incomplete it would be good to update the readme to that effect.
The text was updated successfully, but these errors were encountered: