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 @@ -388,7 +388,15 @@ private void InferKeysFromLookups()
var lookupFieldDefinitions =
schema.Types
.OfType<MutableComplexTypeDefinition>()
.SelectMany(t => t.Fields.AsEnumerable().Where(f => f.Directives.ContainsName(Lookup)));
.SelectMany(t => t.Fields.AsEnumerable().Where(f =>
{
if (f.Arguments.Count == 0 || f.Type.IsNonNullType() || f.Type.IsListType())
{
return false;
}

return f.Directives.ContainsName(Lookup);
}));

foreach (var lookupFieldDefinition in lookupFieldDefinitions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,44 @@ type Person {
Assert.False(schema.Types["Person"].Directives.ContainsName(WellKnownDirectiveNames.Key));
}

[Fact]
public void Preprocess_InferKeysFromLookups_DoesNotApplyToInvalidLookups()
{
// arrange
var sourceSchemaText =
new SourceSchemaText(
"A",
"""
type Query {
personById(id1: ID!): Person @lookup
personByIdNoArguments: Person @lookup
personByIdNonNull(id2: ID!): Person! @lookup
personByIdListType(id3: ID!): [Person] @lookup
}
Comment thread
glen-84 marked this conversation as resolved.

type Person {
id: ID!
}
""");
var compositionLog = new CompositionLog();
var sourceSchemaParser = new SourceSchemaParser(sourceSchemaText, compositionLog);
var schema = sourceSchemaParser.Parse().Value;
var preprocessor =
new SourceSchemaPreprocessor(
schema,
[],
compositionLog);

// act
var result = preprocessor.Preprocess();

// assert
Assert.True(result.IsSuccess);
Assert.Single(
schema.Types["Person"].Directives.Where(
d => d.Name == WellKnownDirectiveNames.Key).ToArray());
}

[Fact]
public void Preprocess_InheritInterfaceKeysEnabled_InheritsInterfaceKeys()
{
Expand Down
Loading