Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -1272,7 +1272,7 @@ public IEnumerable<SharedType> InterfaceConnection()
=> [new Discussion(1)];

[Lookup]
public Author GetAuthorById(int id) => new Author(id);
public Author? GetAuthorById(int id) => new Author(id);
}

[InterfaceType]
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public static class SourceSchema2
public class Query
{
[Lookup]
public OtherInterface GetOtherInterface(int id)
public OtherInterface? GetOtherInterface(int id)
=> new Author(id, id * 5);

[Lookup]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public class Query
};

[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[UsePaging]
Expand Down Expand Up @@ -684,12 +684,12 @@ public Query()

[Internal]
[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[Internal]
[Lookup]
public Author GetAuthorById(int id)
public Author? GetAuthorById(int id)
=> _authors[id];

[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class Query
};

[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[UsePaging]
Expand Down Expand Up @@ -128,12 +128,12 @@ public Query()

[Internal]
[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[Internal]
[Lookup]
public Author GetAuthorById(int id)
public Author? GetAuthorById(int id)
=> _authors[id];

[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ public class Query
};

[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

public string GetInaccessibleText(
Expand All @@ -943,7 +943,7 @@ public class Query

[Internal]
[Lookup]
public Author GetAuthorById(int id)
public Author? GetAuthorById(int id)
=> _authors[id];

public SomeEnum GetEnumField(SomeEnum value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public class Query
};

[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[UsePaging]
Expand Down Expand Up @@ -578,7 +578,7 @@ public class Query

[Internal]
[Lookup]
public Author GetAuthorById(int id)
public Author? GetAuthorById(int id)
=> _authors[id];

[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public sealed class ReviewsQuery
=> ReviewRepository.GetById(id);

[Lookup, Internal]
public ReviewProduct GetProduct([ID] string upc)
public ReviewProduct? GetProduct([ID] string upc)
=> new() { Upc = upc };

[Lookup, Internal]
public ReviewUser GetUser([ID] string id)
public ReviewUser? GetUser([ID] string id)
=> new() { Id = id };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class InternalLookups
};

[Lookup]
public Author GetAuthorById([ID] int id)
public Author? GetAuthorById([ID] int id)
=> _authors[id];
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public class InternalLookups
};

[Lookup, Internal]
public Author GetAuthor([Is("{ id } | { name }")] AuthorByInput by)
public Author? GetAuthor([Is("{ id } | { name }")] AuthorByInput by)
{
if (by.Id is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static class SourceSchema2
public class Query
{
[Internal, Lookup]
public Book GetBookById(int id) => new(id, "Abc");
public Book? GetBookById(int id) => new(id, "Abc");
}

public record Book(int Id, string Author);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class Query
};

[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[UsePaging]
Expand Down Expand Up @@ -182,12 +182,12 @@ public Query()

[Internal]
[Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
=> _books[id];

[Internal]
[Lookup]
public Author GetAuthorById(int id)
public Author? GetAuthorById(int id)
=> _authors[id];

[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,48 +587,6 @@ public async Task Error_On_Lookup_Leaf_In_List_NonNull(ErrorHandlingMode onError
await MatchSnapshotAsync(gateway, request, result, postFix: "OnError_" + onError);
}

[Theory]
[InlineData(ErrorHandlingMode.Propagate)]
[InlineData(ErrorHandlingMode.Null)]
public async Task No_Data_And_Error_With_Path_For_Lookup_Field_NonNull(ErrorHandlingMode onError)
{
// arrange
using var server1 = CreateSourceSchema(
"A",
b => b.AddQueryType<SourceSchema1.Query>());

using var server2 = CreateSourceSchema(
"B",
b => b.AddQueryType<SourceSchema4.Query>());

using var gateway = await CreateCompositeSchemaAsync(
[
("A", server1),
("B", server2)
]);

// act
using var client = GraphQLHttpClient.Create(gateway.CreateClient());

var request = new OperationRequest(
"""
{
topProduct {
price
name
}
}
""",
onError: onError);

using var result = await client.PostAsync(
request,
new Uri("http://localhost:5000/graphql"));

// assert
await MatchSnapshotAsync(gateway, request, result, postFix: "OnError_" + onError);
}

[Theory]
[InlineData(ErrorHandlingMode.Propagate)]
[InlineData(ErrorHandlingMode.Null)]
Expand Down Expand Up @@ -993,7 +951,7 @@ public static class SourceSchema4
public class Query
{
[Lookup]
public Product GetProductById(int id, IResolverContext context)
public Product? GetProductById(int id, IResolverContext context)
=> throw new GraphQLException(ErrorBuilder.New().SetMessage("Could not resolve Product")
.SetPath(context.Path).Build());
}
Expand Down Expand Up @@ -1023,7 +981,7 @@ public static class SourceSchema6
public class Query
{
[Lookup]
public Product GetProductById(int id) => new(id);
public Product? GetProductById(int id) => new(id);
}

public record Product(int Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public record Book(int Id, string Title);
public class Query
{
[Internal, Lookup]
public Book GetBookById(int id)
public Book? GetBookById(int id)
{
switch (id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down Expand Up @@ -139,7 +139,7 @@ sourceSchemas:
}

type Query {
otherInterface(id: Int!): OtherInterface! @lookup
otherInterface(id: Int!): OtherInterface @lookup
discussionById(id: ID!): Discussion @lookup @internal
}
interactions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down Expand Up @@ -139,7 +139,7 @@ sourceSchemas:
}

type Query {
otherInterface(id: Int!): OtherInterface! @lookup
otherInterface(id: Int!): OtherInterface @lookup
discussionById(id: ID!): Discussion @lookup @internal
}
interactions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down Expand Up @@ -130,7 +130,7 @@ sourceSchemas:
}

type Query {
otherInterface(id: Int!): OtherInterface! @lookup
otherInterface(id: Int!): OtherInterface @lookup
discussionById(id: ID!): Discussion @lookup @internal
}
interactions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ sourceSchemas:
"Returns the elements in the list that come before the specified cursor."
before: String
): InterfaceConnectionConnection
authorById(id: Int!): Author! @lookup
authorById(id: Int!): Author @lookup
}
interactions:
- request:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sourceSchemas:
}

type Query {
bookById(id: Int!): Book! @lookup
bookById(id: Int!): Book @lookup
books(
"Returns the first _n_ elements from the list."
first: Int
Expand Down Expand Up @@ -136,8 +136,8 @@ sourceSchemas:
}

type Query {
bookById(id: Int!): Book! @internal @lookup
authorById(id: Int!): Author! @internal @lookup
bookById(id: Int!): Book @internal @lookup
authorById(id: Int!): Author @internal @lookup
authors(
"Returns the first _n_ elements from the list."
first: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sourceSchemas:
}

type Query {
bookById(id: Int!): Book! @lookup
bookById(id: Int!): Book @lookup
books(
"Returns the first _n_ elements from the list."
first: Int
Expand Down Expand Up @@ -144,8 +144,8 @@ sourceSchemas:
}

type Query {
bookById(id: Int!): Book! @internal @lookup
authorById(id: Int!): Author! @internal @lookup
bookById(id: Int!): Book @internal @lookup
authorById(id: Int!): Author @internal @lookup
authors(
"Returns the first _n_ elements from the list."
first: Int
Expand Down
Loading
Loading