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

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

@fry95116

Description

@fry95116

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions