Feature: Add support for custom GraphQL scalars `@gql(scalars: { website: "AWSURL" })`
Tenrys opened this issue · comments
Right now it seems like only fields that are named url
or email
have been hardcoded to use the AWSURL
and AWSEmail
scalar types from AWS, however I would like to be able to use these types on fields like urlPhoto
or something like secondaryEmail
.
As seen here:
prisma-appsync/packages/generator/src/compiler.ts
Lines 859 to 868 in 37b4a68
Would it be possible to use triple slash comments in the Prisma schema to define which fields turn up as what scalar types in the GraphQL schema?
Possibly yes, but would need to find the right syntax...
There is already a custom notation in place (not documented yet) that allows customising the generated GraphQL schema.
/// @gql(queries: { list: null, count: "countyPosts" }, fields: { text: null }, subscriptions: null)
model Post {
text String?
urlPhoto String?
}
The above notation equals to:
- Remove
listPosts
- Rename
countPosts
tocountyPosts
- Remove
text
field - Remove all subscriptions
One option could be:
/// @gql(scalars: { urlPhoto: "AWSURL" })
model Post {
urlPhoto String?
}
Implementing the above would be quite simple, as the code to read the @gql
directive is already in place.
What do you think?
I think that makes sense yes! Until documentation gets written, is there a way to know where exactly the code involving that custom notation is in place?
Parsing the @gql
directive as a JSON object is done here:
prisma-appsync/packages/generator/src/compiler.ts
Lines 367 to 375 in 37b4a68
The following is the config object where to add _scalars: gqlObject?.scalars || {}
:
prisma-appsync/packages/generator/src/compiler.ts
Lines 393 to 406 in 37b4a68
Here is where the check to ignore fields is done:
prisma-appsync/packages/generator/src/compiler.ts
Lines 544 to 567 in 37b4a68
For example, we could do:
const scalar = gqlConfig?._scalars?.[field.name] || this.getFieldScalar(field)
Will be released as part of 1.0.0-rc.6
(you can also try it now with prisma-appsync@1.0.0-preview.6.6
).