Skip to content

Simplify Query Argument Syntax #27

@Michannne

Description

@Michannne

Is your feature request related to a problem? Please describe.
Current query arg syntax is unwiedly, and involves the use of an extension method to convert a C# type into a graph type. Yes, it should be up to the user to supply the correct graph-type, but there should be an easier way so user does not have to think too much of the type or conversions before passing it in.

Describe the solution you'd like
Something simple, and easy for the user without giving up their control of the type being passed, but without conversion, such as:

services.AddGraphQL()
.Query<Author>(
    () => new Query()
    {
        Expression = "author",
        Args = new ArgList() {
			["authorId"] = (long authorId) => {
				DefaultValue = 0,
				Description = "The Author to be searched"
			},
			["bookId"] = (long bookId) => {
				DefaultValue = 0,
				Description = "The Book to be searched"
			},
			["bookName"] = (string bookName) => {
				DefaultValue = null,
				Description = "The name of the Book to be searched"
			},
		},
        Resolver = (context) => authorRepo.GetAll().Where(a => a.AuthorId == (long)context.Arguments["authorId"])
    })
.Build()

Describe alternatives you've considered
Improving the conversion syntax may also be helpful, but the real solution I feel is change how the arguments are added, in GraphQL.NET is equally painful

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions