Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make union input type ? it just have output union type #670

Open
abdelazizmahmoudTechyTypes opened this issue May 24, 2023 · 0 comments
Open

Comments

@abdelazizmahmoudTechyTypes
Copy link

abdelazizmahmoudTechyTypes commented May 24, 2023

`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.

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

No branches or pull requests

1 participant