gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

EPIC: Directive support

Open vektah opened this issue 5 years ago • 5 comments

Here to track the status of directives

:warning: these features are subject to change - if you are using any of these features make sure you have tests on your directives that actually run queries against a graph. :warning:

Execution directives

location implemented obj is
QUERY :heavy_check_mark: https://github.com/99designs/gqlgen/pull/744 *ast.OperationDefinition
MUTATION :heavy_check_mark: https://github.com/99designs/gqlgen/pull/744 *ast.OperationDefinition
SUBSCRIPTION :heavy_check_mark: https://github.com/99designs/gqlgen/pull/744 *ast.OperationDefinition
FIELD :heavy_check_mark: https://github.com/99designs/gqlgen/pull/756 parent type
FRAGMENT_DEFINITION :no_entry:
FRAGMENT_SPREAD :no_entry:
INLINE_FRAGMENT :no_entry:

Schema directives

location implemented obj is
SCHEMA :no_entry:
SCALAR :no_entry:
OBJECT :heavy_check_mark: https://github.com/99designs/gqlgen/pull/1117 parent type
FIELD_DEFINITION :heavy_check_mark: parent type
ARGUMENT_DEFINITION :heavy_check_mark: https://github.com/99designs/gqlgen/pull/460 argument bag
INTERFACE :no_entry:
UNION :no_entry:
ENUM :no_entry:
ENUM_VALUE :no_entry:
INPUT_OBJECT :no_entry:
INPUT_FIELD_DEFINITION :heavy_check_mark: parent input

Schema field directives on subscriptions

obj is always nil for any root (Query, Mutation, Subscription) next() returns a channel of the field type

vektah avatar Jun 26 '19 06:06 vektah

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 28 '19 04:08 stale[bot]

Hello, what happen with directive on ARGUMENT_DEFINITION?

dbadura avatar Oct 30 '19 08:10 dbadura

Hi, I've commented on a potential problem with OBJECT directive, here.

dtrckd avatar Jun 28 '20 12:06 dtrckd

Hi, there.

There are a few questions about directives. Commonly most about INPUT_FIELD_DEFINITION. It is marked with a check mark and its input object is a parent object.

  1. The gqlgen generator doesn't allow directives with INPUT_FIELD_DEFINITION on input fields. But allows them on the input fields with FIELD_DEFINITION.
  2. Object received in a directive handler is map[string]interface{}, not a Go object. Is it by design? Why not Go object?
  3. The following directive produce invalid server that panics just before the directive called
directive @allowValueType (field: String!, allow: [ValueTypeAllow!]) on
	INPUT_FIELD_DEFINITION |
	FIELD_DEFINITION # <- have to add

enum ValueType {
	ONE
	TWO
}

input ValueTypeAllow {
	valueType: ValueType!
	allow:     Boolean!
}

input InputValue {
	name:      String!
	valueType: ValueType! @allowValueType (field: "valueType", allow: [
		ValueTypeAllow{valueType: ONE, allow: true},
		ValueTypeAllow{valueType: TWO, allow: true}
	])
}

However, it's okay with the 3rd point if the directive receives strings for example

directive @allowValueType (field: String!, allow: [String!]) on
	INPUT_FIELD_DEFINITION |
	FIELD_DEFINITION # <- have to add

input InputValue {
	name:      String!
	valueType: ValueType! @allowValueType (field: "valueType", allow: [
		"ONE:true",
		"TWO:true"
	])
}

There is repository that represents all of them https://github.com/logrusorgru/gqlif . It can be cloned and executed with go run main.go. Then, trying to execute

mutation a($name: String!, $value: InputValue!) {
    set (name: $name, value: $value) {name valueType}
}

with

{"name": "pew-pew", "value": {"name": "one", "valueType": "ONE"}}

You will got the panic.

Best regards.

logrusorgru avatar Dec 12 '20 13:12 logrusorgru

Have you found a patch yet?

dangolbeeker avatar May 10 '21 03:05 dangolbeeker