-
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
generated .d.ts lacking exports #217
Comments
I would like a flag to switch to export types instead of a global namespace too. Currently do this through the API: const schemaStr = await readFile(GRAPHQL_SCHEMA_PATH, 'utf8')
const schema = buildSchema(schemaStr)
const result = (await graphql(schema, introspectionQuery)) as { data: IntrospectionQuery }
const formatOptions = (await resolveConfig(__dirname, { config: __dirname + '/../prettier.config.js' }))!
const typings =
'export type ID = string\n\n' +
generateNamespace(
'',
result,
{
typeMap: {
...DEFAULT_TYPE_MAP,
ID: 'ID',
},
},
{
generateNamespace: (name: string, interfaces: string) => interfaces,
interfaceBuilder: (name: string, body: string) =>
'export ' + DEFAULT_OPTIONS.interfaceBuilder(name, body),
enumTypeBuilder: (name: string, values: string) =>
'export ' + DEFAULT_OPTIONS.enumTypeBuilder(name, values),
typeBuilder: (name: string, body: string) => 'export ' + DEFAULT_OPTIONS.typeBuilder(name, body),
wrapList: (type: string) => `${type}[]`,
postProcessor: (code: string) => format(code, { ...formatOptions, parser: 'typescript' }),
}
)
await writeFile(__dirname + '/src/backend/graphqlschema.ts', typings)
} |
i think a flag is reasonable - because we actually do the same thing as @felixfbecker 😄 FWIW there's also interfaceBuilder: (name: string, body: string) => DEFAULT_OPTIONS.exportFunction(DEFAULT_OPTIONS.interfaceBuilder(name, body)) |
Love the module! I currently use a shell script to perform the transformation. Looking forward to a first class solution. #!/usr/bin/env sh
sed -i -e 's/interface /export interface /g' graphqlTypes.d.ts
sed -i -e 's/const /export const /g' graphqlTypes.d.ts
sed -i -e 's/declare namespace GQL {//g' graphqlTypes.d.ts
sed -i -e '/__typename/c\\t\t__typename: string | null' graphqlTypes.d.ts
sed -i -e 's/^}//g' graphqlTypes.d.ts |
Hi, I used the cli tool to generate a .d.ts file.
Everything works except the generated file doesn't have any
export
. I'm looking at the examples and expecting that it should have aexport default [namespace]
?I am using a command like this:
gql2ts build/schemas.json -o ../common/models/gql_schemas.d.ts
thank you!
The text was updated successfully, but these errors were encountered: