gqlparser icon indicating copy to clipboard operation
gqlparser copied to clipboard

Nested field arguments don't seem to be used for conflict validation

Open berstend opened this issue 6 years ago • 0 comments

Hi there,

this might be related to #107 but I figured it would be better to open a new issue as it's related to field arguments.

The following query will raise an error as expected:

{
  country(code: "DE") {
    name
  }
  country(code: "US") {
    name
  }
}

panic: input:6: Fields "country" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional.

Whereas the same query with nested arguments will not:

{
  countryWhere(where: {code: "DE"}) {
    name
  }
  countryWhere(where: {code: "US"}) {
    name
  }
}

Full test case:

package main

import (
	"fmt"

	"github.com/vektah/gqlparser"
	"github.com/vektah/gqlparser/ast"
)

func main() {
	typedef := `
		type Country {
			name: String
		}

		type Query {
			country(code: String): Country
			countryWhere(where: CountryWhereUniqueInput!): Country
		}

		input CountryWhereUniqueInput {
			code: String
		}
	`
	// query := `
	// 	{
	// 		country(code: "DE") {
	// 			name
	// 		}
	// 		country(code: "US") {
	// 			name
	// 		}
	// 	}
	// `
	query := `
		{
			countryWhere(where: {code: "DE"}) {
				name
			}
			countryWhere(where: {code: "US"}) {
				name
			}
		}
	`

	schema, schemaErr := gqlparser.LoadSchema(&ast.Source{
		Input: typedef,
	})
	if schemaErr != nil {
		panic(schemaErr)
	}

	doc, queryErr := gqlparser.LoadQuery(schema, query)
	if queryErr != nil {
		panic(queryErr)
	}

	fmt.Println(schema, doc)
}

Is this issue of the same origin as #107 or a different beast?

Thanks for the all the great work with gqlparser!

berstend avatar Aug 15 '19 13:08 berstend