With Grafbase, you can seamlessly connect any OpenAPI or GraphQL API, enabling the creation of a single unified GraphQL API.
Previously, the generated API included all queries and fields by default. However, the latest enhancement empowers you to exclude specific fields from the generated schema as per your needs!
Here's how you can exclude the field email
from the StripeCustomer
type:
import { config, connector, graph } from '@grafbase/sdk'
const g = graph.Standalone()
const stripe = connector.OpenAPI({
schema:
'https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json',
transforms: schema => {
schema.exclude('StripeCustomer.email')
},
})
export default config({
graph: g,
})
You can also hide individual fields from all top-level queries:
import { config, connector, graph } from '@grafbase/sdk'
const g = graph.Standalone()
const stripe = connector.OpenAPI({
schema:
'https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json',
transforms: schema => {
schema.exclude('Query.*.customer')
},
})
export default config({
graph: g,
})
Finally you can also exclude a set of fields from a type:
import { config, connector, graph } from '@grafbase/sdk'
const g = graph.Standalone()
const stripe = connector.OpenAPI({
schema:
'https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json',
transforms: schema => {
schema.exclude('StripeCustomer.{email,name}')
},
})
export default config({
graph: g,
})
If you wanted to create a read-only GraphQL API you can exclude all mutations using the following wildcard:
import { config, connector, graph } from '@grafbase/sdk'
const g = graph.Standalone()
const stripe = connector.OpenAPI({
schema:
'https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json',
transforms: schema => {
schema.exclude('Mutation.*')
},
})
export default config({
graph: g,
})
This is the first of many updates coming to schema transforms. Stay tuned for more updates.
We'd love to hear your feedback and ideas, so join us on Discord.