-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding failing test for fusion query planner
- Loading branch information
Showing
10 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace HotChocolate.Fusion.Shared.Authors; | ||
|
||
public class Author | ||
{ | ||
public string Id { get; set;} | ||
|
||
public string Name { get; set; } | ||
|
||
public string Bio { get; set;} | ||
|
||
public Author(string id, string name, string bio) { | ||
this.Id = id; | ||
this.Name = name; | ||
this.Bio = bio; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/HotChocolate/Fusion/test/Shared/Authors/AuthorQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace HotChocolate.Fusion.Shared.Authors; | ||
|
||
[GraphQLName("Query")] | ||
public sealed class AuthorQuery | ||
{ | ||
public Author? AuthorById( | ||
string id, | ||
[Service] AuthorRepository repository) | ||
=> repository.GetAuthorById(id); | ||
|
||
public IEnumerable<Author> Authors(int limit, [Service] AuthorRepository repository) | ||
=> repository.GetAuthors(limit); | ||
|
||
public Book BookByAuthorId( | ||
string authorId, | ||
[Service] AuthorRepository repository) { | ||
Author author = repository.GetAuthorById(authorId); | ||
return new Book(authorId, author); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/HotChocolate/Fusion/test/Shared/Authors/AuthorRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace HotChocolate.Fusion.Shared.Authors; | ||
|
||
public sealed class AuthorRepository | ||
{ | ||
private readonly Dictionary<string, Author> _authors; | ||
|
||
public AuthorRepository() | ||
{ | ||
_authors = new[] | ||
{ | ||
new Author("1", "First author", "The first author") | ||
}.ToDictionary(t => t.Id); | ||
} | ||
|
||
public IEnumerable<Author> GetAuthors(int limit) | ||
=> _authors.Values.OrderBy(t => t.Id).Take(limit); | ||
|
||
public Author? GetAuthorById(string id) | ||
=> _authors.TryGetValue(id, out var author) | ||
? author | ||
: null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
namespace HotChocolate.Fusion.Shared.Authors; | ||
|
||
public class Book | ||
{ | ||
|
||
public string AuthorId { get; set;} | ||
|
||
public Author Author {get; set; } | ||
|
||
public Book(string authorId, Author author) { | ||
this.AuthorId = authorId; | ||
this.Author = author; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace HotChocolate.Fusion.Shared.Books; | ||
|
||
|
||
public class Author | ||
{ | ||
public string Id { get; set;} | ||
|
||
public IEnumerable<Book> Books { get; set; } | ||
|
||
public Author(string id, IEnumerable<Book> books) { | ||
this.Id = id; | ||
this.Books = books; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace HotChocolate.Fusion.Shared.Books; | ||
|
||
public class Book | ||
{ | ||
public string Id { get; set;} | ||
|
||
public string AuthorId { get; set;} | ||
|
||
public string Title {get; set; } | ||
|
||
|
||
public Book(string id, string authorId, string title) { | ||
this.Id = id; | ||
this.AuthorId = authorId; | ||
this.Title = title; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace HotChocolate.Fusion.Shared.Books; | ||
|
||
[GraphQLName("Query")] | ||
public sealed class BookQuery | ||
{ | ||
public Book? BookById( | ||
string id, | ||
[Service] BookRepository repository) | ||
=> repository.GetBookById(id); | ||
|
||
public IEnumerable<Book> Books(int limit, [Service] BookRepository repository) | ||
=> repository.GetBooks(limit); | ||
|
||
public Author authorById( | ||
string id, | ||
[Service] BookRepository repository) | ||
=> new Author(id, repository.GetBooksByAuthorId(id)); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/HotChocolate/Fusion/test/Shared/Books/BookRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace HotChocolate.Fusion.Shared.Books; | ||
|
||
public sealed class BookRepository | ||
{ | ||
private readonly Dictionary<string, Book> _books; | ||
|
||
public BookRepository() | ||
{ | ||
_books = new[] | ||
{ | ||
new Book("1", "1", "The first book") | ||
}.ToDictionary(t => t.Id); | ||
} | ||
|
||
public IEnumerable<Book> GetBooks(int limit) | ||
=> _books.Values.OrderBy(t => t.Id).Take(limit); | ||
|
||
public Book? GetBookById(string id) | ||
=> _books.TryGetValue(id, out var book) | ||
? book | ||
: null; | ||
|
||
public IEnumerable<Book> GetBooksByAuthorId(string authorId) | ||
=> _books.Values.Where(b => b.AuthorId.Equals(authorId)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters