graph-gophers / graphql-go

GraphQL server with a focus on ease of use
BSD 2-Clause "Simplified" License
4.64k stars 491 forks source link

Check for required fields while parsing the schema #594

Closed k4n4ry closed 1 year ago

k4n4ry commented 1 year ago

fixes: #548

package main

import (
    "log"
    "net/http"

    graphql "github.com/graph-gophers/graphql-go"
    "github.com/graph-gophers/graphql-go/relay"
)

type query struct{}

func (_ *query) Hello(args struct{ ID *graphql.ID }) string { return "Hello, world!" }

func main() {
    s := `
                type Query {
                        hello(id: ID!): String!
                }
        `
    schema := graphql.MustParseSchema(s, &query{})
    http.Handle("/query", &relay.Handler{Schema: schema})
    log.Fatal(http.ListenAndServe(":8080", nil))
}

When running the above, the following error happen, and exit.

panic: field "ID" must be a non-pointer since the parameter is required
pavelnikolov commented 1 year ago

Thank you for your contribution!