-
Given the following schemaCustomization: exports.createSchemaCustomization = ({ actions }) => {
const { createFieldExtension, createTypes } = actions;
createFieldExtension({
name: "currencyFormat",
description: `Add currency formatting options`,
args: {
formatCurrency: `Boolean`,
},
extend(options, fieldConfig) {
return {
...fieldConfig.args,
args: {
formatCurrency: {
type: `Boolean`,
description: `Formats price to a currency string`
},
},
async resolve(source, args, context, info) {
const resolver = fieldConfig.resolve || context.defaultFieldResolver
const price = await resolver(source, args, context, info)
return args.formatCurrency ? "some_formatted_string" : price
},
}
},
})
createTypes(schema);
}; and the following schema: type SomeType implements Node @dontInfer {
price: Float! @currencyFormat
} I want to be able to query the
I feel like this is exactly what Gatsby's @dateFormat directive is already doing when you pass it |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @herecydev Thanks for this question! The field type cannot change after it is defined in the schema. The only way you can do this is by setting a custom scalar type on your field. Gatsby includes the most general type: |
Beta Was this translation helpful? Give feedback.
Hey @herecydev
Thanks for this question! The field type cannot change after it is defined in the schema. The only way you can do this is by setting a custom scalar type on your field. Gatsby includes the most general type:
JSON
(Date
is another example but it's always resolves to string). Technically, you can introduce your own custom scalar type via schema customization (an example) but this is not documented and I would generally recommend staying away from custom scalar types even in regular GraphQL APIs.