question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

customise generated type names in graphql schema

See original GitHub issue

Hi. It will be cool to let a developer select which style of schema’s root resolver and type names to use. Or let him override it in a console (separately for an object and arrays). In my case, I already have a frontend on ApolloStack (about 60000 lines of code) + backend on JoinMonster, and it’s too hard to replace joinMonster to Hasura, because I need to transform schema, like this:

export default async function getSchema() {
	const link = makeHttpAndWsLink(HASURA_GRAPHQL_ENGINE_URL, HASURA_ACCESS_KEY && { 'x-hasura-access-key': HASURA_ACCESS_KEY })

	const schema = makeRemoteExecutableSchema({
		schema: await introspectSchema(link),
		link
	})

	return transformSchema(schema, [
		new RenameTypes(type => pluralize.singular(capitalize(camelCase(type)))),
		new RenameRootFields((operation, name) => {
			let newName = name

			if (name.includes('_by_pk')) {
				newName = pluralize.singular(newName.replace('_by_pk', ''))
			}

			return camelCase(newName)
		})
	])
}

I want to:

  • Type names must be in camelcase style
  • Type names must begin with a capital letter
  • Type names must be in the singular (even if the table name is in the plural) because it describes one object
  • Root resolvers names must be in camelcase style
  • Root resolvers names which returning arrays must be in the plural
  • Root resolvers names which returning an object must be in the singular (_by_pk, for example)

Example: Before:

user_parties: [user_parties!]!
user_parties_by_pk: user_parties

After:

userParties: [UserParty!]!
userParty: UserParty

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:23 (13 by maintainers)

github_iconTop GitHub Comments

34reactions
revskill10commented, Nov 5, 2018

I don’t think camelCase is actually useful. In my case, i use user_parties as translation key for i18n.

11reactions
beepsoftcommented, Nov 2, 2019

@coco98, @0x777 is this still planned to be supported?

Also, we should allow aliasing of the postgres schema names so that people can change the prefixing behaviour. For example, being able to disable schema name prefixing altogether.

The custom_root_fields and custom_column_names customizations work great added by #2509, but it would be great to have the same kind of customization for the type names/prefixes as well.

Is there an issue or PR where this is being implemented?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics
This schema defines a hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which...
Read more >
Customizing the GraphQL Schema - Gatsby
This guide is aimed at plugin authors, users trying to fix GraphQL schemas created by automatic type inference, developers optimizing builds for larger ......
Read more >
Schemas and Types - GraphQL
Most of the types in your schema will be object types. name and appearsIn are fields on the ... there is also a...
Read more >
Customise auto-generated field names | Hasura GraphQL Docs
Head to the Data -> [table-name] -> Modify . On the relevant field, click Edit and change the GraphQL field name to a...
Read more >
Automatically generate Typescript types for your GraphQL ...
Great! so now we can start defining the schema for our API. Create a new file named type-defs.ts and add the types for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found