Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

struct tag 'optional' is not work for query args #508

Open
fry95116 opened this issue Jan 27, 2022 · 0 comments
Open

struct tag 'optional' is not work for query args #508

fry95116 opened this issue Jan 27, 2022 · 0 comments

Comments

@fry95116
Copy link

it seems that the struct tag optional is not working

go version: 1.17
thunder version: github.com/samsarahq/thunder v0.5.0
minial demo:

package main

import (
	"net/http"

	"github.com/samsarahq/thunder/graphql"
	"github.com/samsarahq/thunder/graphql/introspection"
	"github.com/samsarahq/thunder/graphql/schemabuilder"
)

func main() {
	schema := schemabuilder.NewSchema()

	type Inner struct {
		OptionalValue string
		RequiredValue string
	}

	query := schema.Query()
	query.FieldFunc("inner", func(input struct {
		OptionalInput string `graphql:",optional"`
		RequiredInput string
	}) Inner {
		return Inner{
			OptionalValue: input.OptionalInput,
			RequiredValue: input.RequiredInput,
		}
	})

	builtSchema := schema.MustBuild()
	introspection.AddIntrospectionToSchema(builtSchema)

	http.Handle("/graphql", graphql.HTTPHandler(builtSchema))

	if err := http.ListenAndServe(":3030", nil); err != nil {
		panic(err)
	}

}

and in Graphql playground, it showed that arg OptionalInput is required

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant