customise generated type names in graphql schema
See original GitHub issueHi. 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:
- Created 5 years ago
- Reactions:11
- Comments:23 (13 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think
camelCase
is actually useful. In my case, i useuser_parties
as translation key for i18n.@coco98, @0x777 is this still planned to be supported?
The
custom_root_fields
andcustom_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!