-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from graphql-dotnet/enums-errors-examples
Version 1.2.1
- Loading branch information
Showing
29 changed files
with
701 additions
and
16 deletions.
There are no files selected for viewing
Submodule graphql-dotnet
updated
2 files
+4 −0 | src/GraphQL/Execution/ExecutionError.cs | |
+10 −1 | src/GraphQL/Execution/ExecutionResultJsonConverter.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,11 @@ | ||
namespace GraphQL.Conventions.Tests.Server.Data | ||
{ | ||
public class AuthorDto | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
} | ||
} |
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 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Data | ||
{ | ||
public class BookDto | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Title { get; set; } | ||
|
||
public List<int> AuthorIds { get; set; } | ||
|
||
public DateTime? ReleaseDate { get; set; } | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
samples/SimpleWebApp/Data/Repositories/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,86 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Data.Repositories | ||
{ | ||
public class AuthorRepository : IAuthorRepository | ||
{ | ||
private readonly Dictionary<int, AuthorDto> _authors = new Dictionary<int, AuthorDto> | ||
{ | ||
{ | ||
1, | ||
new AuthorDto | ||
{ | ||
Id = 1, | ||
FirstName = "Benny", | ||
LastName = "Frank", | ||
} | ||
}, | ||
{ | ||
2, | ||
new AuthorDto | ||
{ | ||
Id = 2, | ||
FirstName = "Amalie", | ||
LastName = "Jones", | ||
} | ||
}, | ||
{ | ||
3, | ||
new AuthorDto | ||
{ | ||
Id = 3, | ||
FirstName = "Stewart", | ||
LastName = "Clarksen", | ||
} | ||
}, | ||
{ | ||
4, | ||
new AuthorDto | ||
{ | ||
Id = 4, | ||
FirstName = "Sony", | ||
LastName = "Mahony", | ||
} | ||
}, | ||
}; | ||
|
||
private int _nextId = 1; | ||
|
||
public int AddAuthor(AuthorDto author) | ||
{ | ||
var id = _nextId++; | ||
_authors[id] = author; | ||
_authors[id].Id = id; | ||
return id; | ||
} | ||
|
||
public AuthorDto GetAuthorById(int id) | ||
{ | ||
AuthorDto author; | ||
if (_authors.TryGetValue(id, out author)) | ||
{ | ||
return author; | ||
} | ||
return null; | ||
} | ||
|
||
public IEnumerable<AuthorDto> GetAuthorsByIds(List<int> ids) | ||
{ | ||
foreach (var id in ids) | ||
{ | ||
yield return GetAuthorById(id); | ||
} | ||
} | ||
|
||
public IEnumerable<AuthorDto> SearchForAuthorsByLastName(string searchString) | ||
{ | ||
foreach (var author in _authors.Values) | ||
{ | ||
if (author.LastName?.ToLower()?.Contains(searchString?.ToLower()) ?? false) | ||
{ | ||
yield return 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,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Data.Repositories | ||
{ | ||
public class BookRepository : IBookRepository | ||
{ | ||
private readonly Dictionary<int, BookDto> _books = new Dictionary<int, BookDto> | ||
{ | ||
{ | ||
1, | ||
new BookDto | ||
{ | ||
Id = 1, | ||
Title = "A Lone Wolf in the Forest", | ||
ReleaseDate = new DateTime(1985, 1, 1), | ||
AuthorIds = new List<int> { 1, 2 } | ||
} | ||
}, | ||
{ | ||
2, | ||
new BookDto | ||
{ | ||
Id = 2, | ||
Title = "Surfer Boy", | ||
ReleaseDate = new DateTime(1998, 1, 1), | ||
AuthorIds = new List<int> { 2 } | ||
} | ||
}, | ||
{ | ||
3, | ||
new BookDto | ||
{ | ||
Id = 3, | ||
Title = "GraphQL, a Love Story", | ||
ReleaseDate = new DateTime(2015, 1, 1), | ||
AuthorIds = new List<int> { 4 } | ||
} | ||
}, | ||
{ | ||
4, | ||
new BookDto | ||
{ | ||
Id = 4, | ||
Title = "Dare I Say What?", | ||
ReleaseDate = new DateTime(2009, 1, 1), | ||
AuthorIds = new List<int> { 3, 4 } | ||
} | ||
}, | ||
}; | ||
|
||
private int _nextId = 5; | ||
|
||
public int AddBook(BookDto book) | ||
{ | ||
var id = _nextId++; | ||
_books[id] = book; | ||
_books[id].Id = id; | ||
return id; | ||
} | ||
|
||
public BookDto GetBookById(int id) | ||
{ | ||
BookDto book; | ||
if (_books.TryGetValue(id, out book)) | ||
{ | ||
return book; | ||
} | ||
return null; | ||
} | ||
|
||
public IEnumerable<BookDto> GetBooksByIds(List<int> ids) | ||
{ | ||
foreach (var id in ids) | ||
{ | ||
yield return GetBookById(id); | ||
} | ||
} | ||
|
||
public IEnumerable<BookDto> SearchForBooksByTitle(string searchString) | ||
{ | ||
foreach (var book in _books.Values) | ||
{ | ||
if (book.Title?.ToLower()?.Contains(searchString?.ToLower()) ?? false) | ||
{ | ||
yield return book; | ||
} | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
samples/SimpleWebApp/Data/Repositories/IAuthorRepository.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,15 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Data.Repositories | ||
{ | ||
public interface IAuthorRepository | ||
{ | ||
int AddAuthor(AuthorDto author); | ||
|
||
AuthorDto GetAuthorById(int id); | ||
|
||
IEnumerable<AuthorDto> GetAuthorsByIds(List<int> ids); | ||
|
||
IEnumerable<AuthorDto> SearchForAuthorsByLastName(string searchString); | ||
} | ||
} |
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 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Data.Repositories | ||
{ | ||
public interface IBookRepository | ||
{ | ||
int AddBook(BookDto book); | ||
|
||
BookDto GetBookById(int id); | ||
|
||
IEnumerable<BookDto> GetBooksByIds(List<int> ids); | ||
|
||
IEnumerable<BookDto> SearchForBooksByTitle(string searchString); | ||
} | ||
} |
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,26 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace GraphQL.Conventions.Tests.Server | ||
{ | ||
public class DependencyInjector : IDependencyInjector | ||
{ | ||
private readonly Dictionary<TypeInfo, object> _registrations = | ||
new Dictionary<TypeInfo, object>(); | ||
|
||
public void Register<TType>(TType instance) | ||
{ | ||
_registrations.Add(typeof(TType).GetTypeInfo(), instance); | ||
} | ||
|
||
public object Resolve(TypeInfo typeInfo) | ||
{ | ||
object instance; | ||
if (_registrations.TryGetValue(typeInfo, out instance)) | ||
{ | ||
return instance; | ||
} | ||
return 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,21 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace GraphQL.Conventions.Tests.Server | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
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,13 @@ | ||
using GraphQL.Conventions.Relay; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Schema.Input | ||
{ | ||
[Description("Operation for adding a new author.")] | ||
public class AddAuthorParams : IRelayMutationInputObject | ||
{ | ||
public string ClientMutationId { get; set; } | ||
|
||
[Description("The author to add.")] | ||
public NonNull<AuthorInput> Author { get; set; } | ||
} | ||
} |
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,13 @@ | ||
using GraphQL.Conventions.Relay; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Schema.Input | ||
{ | ||
[Description("Operation for adding a new book to the library.")] | ||
public class AddBookParams : IRelayMutationInputObject | ||
{ | ||
public string ClientMutationId { get; set; } | ||
|
||
[Description("The book to add.")] | ||
public NonNull<BookInput> Book { get; set; } | ||
} | ||
} |
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,13 @@ | ||
namespace GraphQL.Conventions.Tests.Server.Schema.Input | ||
{ | ||
[InputType] | ||
[Description("An author")] | ||
public class AuthorInput | ||
{ | ||
[Description("The author's firstname.")] | ||
public string FirstName { get; set; } | ||
|
||
[Description("The author's lastname.")] | ||
public NonNull<string> LastName { get; set; } | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GraphQL.Conventions.Tests.Server.Schema.Input | ||
{ | ||
[InputType] | ||
[Description("A book")] | ||
public class BookInput | ||
{ | ||
[Description("The book's title.")] | ||
public NonNull<string> Title { get; set; } | ||
|
||
[Description("The book's release date.")] | ||
public DateTime? ReleaseDate { get; set; } | ||
|
||
[Description("The IDs of the book's authors.")] | ||
public List<Id> Authors { get; set; } | ||
} | ||
} |
Oops, something went wrong.