Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ public void Handle(SchemaEvent @event, CompositionContext context)
var fieldArgumentValue = (string)isDirective.Arguments[Field].Value!;
var fieldSelectionMapParser = new FieldSelectionMapParser(fieldArgumentValue);
var fieldSelectionMap = fieldSelectionMapParser.Parse();
var inputTypeNode = sourceArgument.Type.ToTypeNode();
var inputTypeDefinition = schema.Types[sourceArgument.Type.AsTypeDefinition().Name];
var inputType = inputTypeNode.RewriteToType(inputTypeDefinition);
var outputTypeNode = sourceField.Type.ToTypeNode();
var outputTypeDefinition = schema.Types[sourceField.Type.AsTypeDefinition().Name];
var outputType = outputTypeNode.RewriteToType(outputTypeDefinition);
var inputType = sourceArgument.Type;
var outputType = sourceField.Type;

var errors = validator.Validate(fieldSelectionMap, inputType, outputType);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@
<data name="SelectionSetValidator_UnionFieldInvalidSelections" xml:space="preserve">
<value>The field '{0}' returns a union type and must only include inline fragment selections.</value>
</data>
<data name="FieldSelectionMapValidator_InvalidFieldParentType" xml:space="preserve">
<value>Expected the parent type of field '{0}' to be a complex type but received '{1}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ protected override ISyntaxVisitorAction Enter(
PathSegmentNode node,
FieldSelectionMapValidatorContext context)
{
if (context.OutputTypes.Peek().NullableType() is IComplexTypeDefinition complexType)
var outputType = context.OutputTypes.Peek();
if (outputType.NullableType() is IComplexTypeDefinition complexType)
{
if (!complexType.Fields.TryGetField(node.FieldName.Value, out var field))
{
Expand All @@ -146,7 +147,7 @@ protected override ISyntaxVisitorAction Enter(
context.Errors.Add(
string.Format(
FieldSelectionMapValidator_FieldMissingTypeCondition,
node.FieldName));
node.FieldName.Value));

return Break;
}
Expand Down Expand Up @@ -201,6 +202,16 @@ protected override ISyntaxVisitorAction Enter(
context.TerminalTypes.Push(field.Type);
}
}
else
{
context.Errors.Add(
string.Format(
FieldSelectionMapValidator_InvalidFieldParentType,
node.FieldName.Value,
outputType));

return Break;
}

if (node.TypeName is { } typeName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,86 @@ type Person {
"The @is directive on argument 'Query.personById(id:)' in schema 'A' "
+ "specifies an invalid field selection against the composed schema."
]
},
// Type of argument does not match field type.
{
[
"""
# Schema A
type Query {
personById(id: Int! @is(field: "id")): Person @lookup
}

type Person {
id: ID!
name: String
}
"""
],
[
"The @is directive on argument 'Query.personById(id:)' in schema 'A' "
+ "specifies an invalid field selection against the composed schema."
]
},
// List output type, Singular input type.
{
[
"""
# Schema A
type Query {
personsById(id: ID! @is(field: "id")): [Person!]! @lookup
}

type Person {
id: ID!
name: String
}
"""
],
[
"The @is directive on argument 'Query.personsById(id:)' in schema 'A' "
+ "specifies an invalid field selection against the composed schema."
]
},
// Singular output type, List input type.
{
[
"""
# Schema A
type Query {
personByIds(ids: [ID!]! @is(field: "id")): Person! @lookup
}

type Person {
id: ID!
name: String
}
"""
],
[
"The @is directive on argument 'Query.personByIds(ids:)' in schema 'A' "
+ "specifies an invalid field selection against the composed schema."
]
},
// List output type, List input type (valid for Fusion v1 batch lookups).
{
[
"""
# Schema A
type Query {
personsByIds(ids: [ID!]! @is(field: "id")): [Person!]! @lookup
}

type Person {
id: ID!
name: String
}
"""
],
[
"The @is directive on argument 'Query.personsByIds(ids:)' in schema 'A' "
+ "specifies an invalid field selection against the composed schema."
]
}
};
}
Expand Down
Loading