Skip to content

Commit

Permalink
add experimental directive
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercactapus committed Dec 20, 2023
1 parent d330a9b commit b5b565c
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
72 changes: 68 additions & 4 deletions graphql2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions graphql2/graph/_directives.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ directive @goField(
name: String # overrides the field name in the generated Go code
omittable: Boolean # creates the field with a wrapper type (graphql.Omittable[T]) with a boolean indicating if the field is null (similar to sql.NullString and friends)
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION

# experimental is used to mark fields as experimental.
#
# Experimental fields are subject to change/removal without warning.
directive @experimental(
flagName: String! # the name of the feature flag to use to enable this field
) on FIELD_DEFINITION
4 changes: 2 additions & 2 deletions graphql2/graph/destinations.graphqls
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extend type Query {
destinationTypes: [DestinationTypeInfo!]!
destinationFieldValidate(input: DestinationFieldValidateInput!): Boolean!
destinationTypes: [DestinationTypeInfo!]! @experimental(flagName: "dest-types")
destinationFieldValidate(input: DestinationFieldValidateInput!): Boolean! @experimental(flagName: "dest-types")
}

input DestinationFieldValidateInput {
Expand Down
7 changes: 6 additions & 1 deletion graphql2/graphqlapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ func isGQLValidation(gqlErr *gqlerror.Error) bool {

func (a *App) Handler() http.Handler {
h := handler.NewDefaultServer(
graphql2.NewExecutableSchema(graphql2.Config{Resolvers: a}),
graphql2.NewExecutableSchema(graphql2.Config{
Resolvers: a,
Directives: graphql2.DirectiveRoot{
Experimental: Experimental,
},
}),
)

type hasTraceKey int
Expand Down
17 changes: 17 additions & 0 deletions graphql2/graphqlapp/directives.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package graphqlapp

import (
"context"

"github.com/99designs/gqlgen/graphql"
"github.com/target/goalert/expflag"
"github.com/target/goalert/validation"
)

func Experimental(ctx context.Context, obj interface{}, next graphql.Resolver, flagName string) (res interface{}, err error) {
if !expflag.ContextHas(ctx, expflag.Flag(flagName)) {
return nil, validation.NewGenericError("experimental flag not enabled")
}

return next(ctx)
}

0 comments on commit b5b565c

Please sign in to comment.