-
-
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 #26 from graphql-dotnet/schema-printer-and-web-ext…
…ensions Fix schema printer, add web extensions, improve attribute registration
- Loading branch information
Showing
13 changed files
with
432 additions
and
24 deletions.
There are no files selected for viewing
Submodule graphql-dotnet
updated
2 files
+4 −0 | src/GraphQL/Execution/ExecutionError.cs | |
+1 −1 | src/GraphQL/Utilities/SchemaPrinter.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
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
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
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 @@ | ||
using System.IO; | ||
|
||
namespace GraphQL.Conventions.Web | ||
{ | ||
public static class Extensions | ||
{ | ||
public static Request ToGraphQLRequest(this Stream stream) => | ||
Request.New(stream); | ||
|
||
public static Response ToResponse(this ExecutionResult result, Request request, GraphQLEngine engine) => | ||
new Response(request, result, engine.SerializeResult(result)); | ||
|
||
public static string IdentifierForTypeOrNull<T>(this Id id) => | ||
id.IsIdentifierForType<T>() ? id.IdentifierForType<T>() : 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,11 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace GraphQL.Conventions.Web | ||
{ | ||
public interface IRequestHandler | ||
{ | ||
Task<Response> ProcessRequest(Request request, IUserContext userContext); | ||
|
||
string DescribeSchema(bool returnJson = false); | ||
} | ||
} |
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,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
using Newtonsoft.Json; | ||
|
||
namespace GraphQL.Conventions.Web | ||
{ | ||
public class Request | ||
{ | ||
static readonly IRequestDeserializer _requestDeserializer = new RequestDeserializer(); | ||
|
||
static readonly Regex _regexSuperfluousWhitespace = | ||
new Regex(@"[ \t\r\n]{1,}", RegexOptions.Multiline | RegexOptions.Compiled); | ||
|
||
readonly string _queryId; | ||
|
||
readonly QueryInput _queryInput; | ||
|
||
readonly Exception _exception; | ||
|
||
public static Request New(Stream stream) | ||
{ | ||
stream.Seek(0, SeekOrigin.Begin); | ||
var requestBody = new StreamReader(stream).ReadToEnd(); | ||
return New(requestBody); | ||
} | ||
|
||
public static Request New(string requestBody) | ||
{ | ||
try | ||
{ | ||
var queryInput = _requestDeserializer.GetQueryFromRequestBody(requestBody); | ||
return New(queryInput); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return InvalidInput(ex); | ||
} | ||
} | ||
|
||
public static Request New(QueryInput queryInput) | ||
{ | ||
return new Request(queryInput); | ||
} | ||
|
||
public static Request InvalidInput(Exception exception) | ||
{ | ||
return new Request(exception); | ||
} | ||
|
||
Request() | ||
{ | ||
_queryId = Guid.NewGuid().ToString(); | ||
} | ||
|
||
Request(QueryInput queryInput) | ||
: this() | ||
{ | ||
_queryInput = queryInput; | ||
} | ||
|
||
Request(Exception exception) | ||
: this() | ||
{ | ||
_exception = exception; | ||
} | ||
|
||
public string QueryId => _queryId; | ||
|
||
public string QueryString => _queryInput?.QueryString ?? string.Empty; | ||
|
||
public Dictionary<string, object> Variables => _queryInput?.Variables; | ||
|
||
public string OperationName => _queryInput?.OperationName; | ||
|
||
public bool IsValid => _exception == null; | ||
|
||
public Exception Error => _exception; | ||
|
||
public string MinifiedQueryString => MinifyString(QueryString); | ||
|
||
public string MinifiedVariablesString => MinifyString(JsonConvert.SerializeObject(Variables)); | ||
|
||
static string MinifyString(string input) | ||
{ | ||
if (input == null) | ||
{ | ||
return string.Empty; | ||
} | ||
return _regexSuperfluousWhitespace.Replace(input, @" ").Trim(); | ||
} | ||
} | ||
} |
Oops, something went wrong.