Skip to content

customise generated type names in graphql schema #981

Closed
@maxpain

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

c/consoleRelated to consolec/serverRelated to serverdesign-rfcPicked up by product design team for RFCk/enhancementNew feature or improve an existing featurep/highcandidate for being included in the upcoming sprint

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions