You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to @Gomes on Discord. This only works for scalar-like types, for composite types you'll need to register separate input and output types (i.e. in addition to calling pgRegisterGqlTypeByTypeId you also need to call pgRegisterGqlInputTypeByTypeId)
importtype{GraphQLType}from"graphql";importtype{Plugin}from"graphile-build";importtype{PgType}from"graphile-build-pg";interfacePgDomainToGqlTypePluginArgs{/** PostgreSQL type identifier, e.g. "my_schema.my_type" */typeIdentifier: string;/** What GraphQL type should we use for this PG type */gqlType: GraphQLType|((build: Build)=>GraphQLType);}/** * Sets the GraphQL type `gqlType` to be used for the PostgreSQL type identified * by `typeIdentifier` */exportfunctionmakePgDomainToGqlTypePlugin({
typeIdentifier,
gqlType,}: PgDomainToGqlTypePluginArgs): Plugin{return(builder)=>{builder.hook("build",(build)=>{const{ namespaceName,entityName: typeName}=build.pgParseIdentifier(typeIdentifier);constpgType=build.pgIntrospectionResultsByKind.type.find((type: PgType)=>type.namespaceName===namespaceName&&type.name===typeName);if(!pgType){thrownewError(`Failed to find the type '${typeIdentifier}'`);}build.pgRegisterGqlTypeByTypeId(pgType.id,()=>typeofgqlType==="function" ? gqlType(build) : gqlType);returnbuild;});};}
The text was updated successfully, but these errors were encountered:
Thanks to
@Gomes
on Discord. This only works for scalar-like types, for composite types you'll need to register separate input and output types (i.e. in addition to callingpgRegisterGqlTypeByTypeId
you also need to callpgRegisterGqlInputTypeByTypeId
)The text was updated successfully, but these errors were encountered: