This package allows you to define a constraint to your graphql input
.
- go >= 1.18
- 99designs/gqlgen >= 0.17
- Add this library to your go project with:
go get -u github.com/jacoz/gqlgen-oneof-directive
go mod tidy
- Add to your
schema.graphqls
file the directive and then use it like the example below:
directive @oneOf on INPUT_OBJECT
# ...
input PaymentRequestInput @oneOf {
card: CardPaymentRequestInput
sepa: SepaPaymentRequestInput
invoice: InvoicePaymentRequestInput
}
- Regenerate the graphql schema with the command
go run github.com/99designs/gqlgen generate
- Load the directive into your graphql server configuration:
c := generated.Config{}
c.Directives.OneOf = oneof.Directive