graphql-go / graphql-go/graphql

make union input type ? it just have output union type

Open
#670 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

`router.AddMutationField("test_union", types.IdType, graphql.FieldConfigArgument{
"input": &graphql.ArgumentConfig{
Type: graphql.NewList(searchInputType),
},
}, UpdateSetting)

type Book struct {
Title string `json:"title"`
Author string `json:"author"`
}

type Movie struct {
Title string `json:"title"`
Director string `json:"director"`
}

var bookType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Book",
Fields: graphql.Fields{
"title": &graphql.Field{
Type: graphql.String,
},
"author": &graphql.Field{
Type: graphql.String,
},
"__typename": &graphql.Field{
Type: graphql.String,
},
},
},
)

var movieType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Movie",
Fields: graphql.Fields{
"title": &graphql.Field{
Type: graphql.String,
},
"director": &graphql.Field{
Type: graphql.String,
}, "__typename": &graphql.Field{
Type: graphql.String,
},
},
},
)

var productUnion = graphql.NewUnion(graphql.UnionConfig{
Name: "Product",
Types: []*graphql.Object{
bookType, movieType,
},
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
switch p.Value.(type) {
case Book:
return bookType
case Movie:
return movieType
default:
return movieType
}
},
})

var searchInputType = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "SearchInput",
Fields: graphql.InputObjectConfigFieldMap{
"product": &graphql.InputObjectFieldConfig{
Type: graphql.NewList(productUnion),
}, "__typename": &graphql.InputObjectFieldConfig{
Type: graphql.String,
},
},
})
`

when make this get Error: Introspection must provide input type for arguments.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.