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

Check for required fields while parsing the schema #594

Merged

Conversation

k4n4ry
Copy link
Contributor

@k4n4ry k4n4ry commented Feb 26, 2023

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

@k4n4ry k4n4ry marked this pull request as ready for review February 26, 2023 04:20
@pavelnikolov pavelnikolov added this to the v1.6.0 milestone Feb 26, 2023
@pavelnikolov pavelnikolov merged commit b1f75d1 into graph-gophers:master Feb 26, 2023
@pavelnikolov
Copy link
Member

Thank you for your contribution!

KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
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

Successfully merging this pull request may close these issues.

Required parameter passes schema validation, but fails at runtime
2 participants