Skip to content

Commit

Permalink
Backport PR #3334 to 20.x (#3355)
Browse files Browse the repository at this point in the history
  • Loading branch information
dondonz committed Oct 23, 2023
1 parent 6c116dc commit 8d42f76
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Expand Up @@ -135,7 +135,7 @@ private void collectFieldsForField(Map<String, Set<FieldAndType>> fieldMap, Grap
GraphQLFieldDefinition fieldDefinition = getVisibleFieldDefinition(fieldsContainer, field);
fieldType = fieldDefinition != null ? fieldDefinition.getType() : null;
}
fieldMap.get(responseName).add(new FieldAndType(field, fieldType, parentType));
fieldMap.get(responseName).add(new FieldAndType(field, fieldType, unwrappedParent));
}

private GraphQLFieldDefinition getVisibleFieldDefinition(GraphQLFieldsContainer fieldsContainer, Field field) {
Expand Down
Expand Up @@ -337,6 +337,7 @@ class OverlappingFieldsCanBeMergedTest extends Specification {
def schema = schema('''
type Dog {
nickname: String
name : String
}
type Query { dog: Dog }
''')
Expand All @@ -349,6 +350,58 @@ class OverlappingFieldsCanBeMergedTest extends Specification {
errorCollector.getErrors()[0].locations == [new SourceLocation(3, 13), new SourceLocation(4, 13)]
}

def 'issue 3332 - Alias masking direct field access non fragment'() {
given:
def query = """
{ dog {
name: nickname
name
}}
"""
def schema = schema('''
type Dog {
name : String
nickname: String
}
type Query { dog: Dog }
''')
when:
traverse(query, schema)

then:
errorCollector.getErrors().size() == 1
errorCollector.getErrors()[0].message == "Validation error (FieldsConflict@[dog]) : 'name' : 'nickname' and 'name' are different fields"
errorCollector.getErrors()[0].locations == [new SourceLocation(3, 13), new SourceLocation(4, 13)]
}

def 'issue 3332 -Alias masking direct field access non fragment with non null parent type'() {
given:
def query = """
query GetCat {
cat {
foo1
foo1: foo2
}
}
"""
def schema = schema('''
type Query {
cat: Cat! # non null parent type
}
type Cat {
foo1: String!
foo2: String!
}
''')
when:
traverse(query, schema)

then:
errorCollector.getErrors().size() == 1
errorCollector.getErrors()[0].message == "Validation error (FieldsConflict@[cat]) : 'foo1' : 'foo1' and 'foo2' are different fields"
errorCollector.getErrors()[0].locations == [new SourceLocation(4, 17), new SourceLocation(5, 17)]
}

def 'conflicting args'() {
given:
def query = """
Expand Down

0 comments on commit 8d42f76

Please sign in to comment.