Package

This package allows you to define a constraint to your graphql input.

Requirements

Setup

  1. Add this library to your go project with:
go get -u github.com/jacoz/gqlgen-oneof-directive
go mod tidy
  1. 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
}
  1. Regenerate the graphql schema with the command
go run github.com/99designs/gqlgen generate
  1. Load the directive into your graphql server configuration:
c := generated.Config{}
c.Directives.OneOf = oneof.Directive