Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sahb1239 committed Jul 27, 2019
2 parents d75e6cf + 63dc74b commit 49dba7e
Show file tree
Hide file tree
Showing 34 changed files with 278 additions and 92 deletions.
2 changes: 1 addition & 1 deletion examples/SAHB.GraphQLClient.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static async Task Main(string[] args)
"https://mpjk0plp9.lp.gql.zone/graphql", HttpMethod.Post);
Console.WriteLine(result.Data.Hero.Name);

// Using dependency injection and concole logging
// Using dependency injection and console logging
var serviceCollection = new ServiceCollection();
serviceCollection
.AddLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Information))
Expand Down
57 changes: 37 additions & 20 deletions src/SAHB.GraphQLClient/Batching/Internal/GraphQLBatchMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,22 @@ public IGraphQLQuery<T> AddQuery<T>(params GraphQLQueryArgument[] arguments)
return new GraphQLBatchQuery<T>(this, identifier);
}

public async Task<T> GetValue<T>(string identitifer)
public Task<T> GetValue<T>(string identifier)
where T : class
{
if (!_isExecuted)
await Execute().ConfigureAwait(false);

if (_result.ContainsErrors)
{
throw new GraphQLErrorException(query: _executedQuery , errors: _result.Errors);
}

// Create new JObject
JObject deserilizeFrom = new JObject();
return GetDeserializedResult<T>(identifier);
}

// Get all fields
foreach (var field in _fields[identitifer])
{
// Add field with previous alias to JObject
deserilizeFrom.Add(field.Inner.Alias, _result.Data[field.Alias]);
}
public async Task<GraphQLDataDetailedResult<T>> GetDetailedValue<T>(string identifier)
where T : class
{
var deserialized = await GetDeserializedResult<T>(identifier);

// Deserilize from
return deserilizeFrom.ToObject<T>();
return new GraphQLDataDetailedResult<T>
{
Data = deserialized,
Headers = _result.Headers
};
}

public async Task Execute()
Expand Down Expand Up @@ -132,7 +125,7 @@ private void UpdateArguments()
}
}

// Update recieved arguments
// Update received arguments
foreach (var argumentsWithIdentitfier in _arguments)
{
foreach (var argument in argumentsWithIdentitfier.Value)
Expand All @@ -142,6 +135,30 @@ private void UpdateArguments()
}
}

private async Task<T> GetDeserializedResult<T>(string identifier)
{
if (!_isExecuted)
await Execute().ConfigureAwait(false);

if (_result.ContainsErrors)
{
throw new GraphQLErrorException(query: _executedQuery, errors: _result.Errors);
}

// Create new JObject
JObject deserilizeFrom = new JObject();

// Get all fields
foreach (var field in _fields[identifier])
{
// Add field with previous alias to JObject
deserilizeFrom.Add(field.Inner.Alias, _result.Data[field.Alias]);
}

// Deserialize from
return deserilizeFrom.ToObject<T>();
}

public bool Executed => _isExecuted;

// ReSharper disable once InconsistentNaming
Expand Down
6 changes: 6 additions & 0 deletions src/SAHB.GraphQLClient/Batching/Internal/GraphQLBatchQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using SAHB.GraphQLClient.Result;

namespace SAHB.GraphQLClient.Batching.Internal
{
Expand All @@ -21,5 +22,10 @@ public Task<T> Execute()
{
return _batch.GetValue<T>(_identitifer);
}

public Task<GraphQLDataDetailedResult<T>> ExecuteDetailed()
{
return _batch.GetDetailedValue<T>(_identitifer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace SAHB.GraphQLClient.Exceptions
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// Exception thrown when duplicate variablenames has been detected in the query arguments. Please doublecheck that you don't supply multiple arguments with the same variableName
/// Exception thrown when duplicate variable names has been detected in the query arguments. Please double check that you don't supply multiple arguments with the same variableName
/// </summary>
public class GraphQLDuplicateVariablesException : GraphQLException
{
public GraphQLDuplicateVariablesException(ICollection<string> duplicateVariableNames) : base("Exception thrown when duplicate variablenames has been detected in the query arguments. Please doublecheck that you don't supply multiple arguments with the same variableName. The duplicated variable names was: " + Environment.NewLine + String.Join(Environment.NewLine, duplicateVariableNames))
public GraphQLDuplicateVariablesException(ICollection<string> duplicateVariableNames) : base("Exception thrown when duplicate variable names has been detected in the query arguments. Please double check that you don't supply multiple arguments with the same variableName. The duplicated variable names was: " + Environment.NewLine + String.Join(Environment.NewLine, duplicateVariableNames))
{
DuplicateVariableNames = new ReadOnlyCollection<string>(duplicateVariableNames.ToList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SAHB.GraphQLClient.Exceptions
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// Throws a new <see cref="GraphQLHttpExecutorServerErrorStatusCodeException"/> which indicates that the GraphQL request returned a non successfull server status code
/// Throws a new <see cref="GraphQLHttpExecutorServerErrorStatusCodeException"/> which indicates that the GraphQL request returned a non successful server status code
/// </summary>
public class GraphQLHttpExecutorServerErrorStatusCodeException : GraphQLException
{
Expand Down
14 changes: 8 additions & 6 deletions src/SAHB.GraphQLClient/Executor/GraphQLHttpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GraphQLHttpExecutor : IGraphQLHttpExecutor
private readonly HttpClient _client;

/// <summary>
/// Initilizes a new instance of a GraphQL executor which executes a query against a http GraphQL server
/// Initializes a new instance of a GraphQL executor which executes a query against a http GraphQL server
/// </summary>
public GraphQLHttpExecutor()
{
Expand All @@ -40,7 +40,7 @@ public async Task<GraphQLDataResult<T>> ExecuteQuery<T>(string query, string url
Logger.LogInformation($"Sending query {query} to GraphQL server on {url} with method {method}");
}

// Initilizes request message
// Initializes request message
var requestMessage = new HttpRequestMessage(method, url)
{
Content = new StringContent(query, Encoding.UTF8, "application/json")
Expand All @@ -67,10 +67,10 @@ public async Task<GraphQLDataResult<T>> ExecuteQuery<T>(string query, string url
}
catch (Exception ex)
{
throw new GraphQLHttpExecutorServerErrorStatusCodeException(response.StatusCode, query, errorResponse, "Response from server was not successfully", ex);
throw new GraphQLHttpExecutorServerErrorStatusCodeException(response.StatusCode, query, errorResponse, "Response from server was not successful", ex);
}

throw new GraphQLHttpExecutorServerErrorStatusCodeException(response.StatusCode, query, errorResponse, "Response from server was not successfully");
throw new GraphQLHttpExecutorServerErrorStatusCodeException(response.StatusCode, query, errorResponse, "Response from server was not successful");
}

// Get response
Expand All @@ -82,9 +82,11 @@ public async Task<GraphQLDataResult<T>> ExecuteQuery<T>(string query, string url
Logger.LogInformation($"Response: {stringResponse}");
}

// Deserilize response
// Deserialize response
var result = JsonConvert.DeserializeObject<GraphQLDataResult<T>>(stringResponse);

result.Headers = response.Headers;

// Logging errors
if (result.ContainsErrors && Logger != null && Logger.IsEnabled(LogLevel.Error))
{
Expand All @@ -93,7 +95,7 @@ public async Task<GraphQLDataResult<T>> ExecuteQuery<T>(string query, string url

return result;
}

#region Logging

private ILoggerFactory _loggerFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/SAHB.GraphQLClient/Executor/IGraphQLHttpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IGraphQLHttpExecutor
/// <summary>
/// Execute the specified GraphQL query
/// </summary>
/// <typeparam name="T">The retun type in the data property</typeparam>
/// <typeparam name="T">The return type in the data property</typeparam>
/// <param name="query">The GraphQL query which should be executed</param>
/// <param name="url">Url to the GraphQL endpoint</param>
/// <param name="method">HttpMethod which should be used for the GraphQL endpoint</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SAHB.GraphQLClient.Extentions
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// Contains extention methods for <see cref="IGraphQLHttpClient"/>
/// Contains extension methods for <see cref="IGraphQLHttpClient"/>
/// </summary>
public static class GraphQLHttpClientExtentions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SAHB.GraphQLClient.Extentions
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// Extentions for the <see cref="IGraphQLQueryGeneratorFromFields"/> interface
/// Extensions for the <see cref="IGraphQLQueryGeneratorFromFields"/> interface
/// </summary>
public static class GraphQLQueryGeneratorFromFieldsExtentions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLArgumentsAttribute : Attribute
{
/// <summary>
/// Initilizes a attribute which defines a argument which is used for a GraphQL field
/// Initializes a attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand All @@ -21,7 +21,7 @@ public GraphQLArgumentsAttribute(string argumentName, string argumentType, strin
}

/// <summary>
/// Initilizes a attribute which defines a argument which is used for a GraphQL field
/// Initializes a attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand All @@ -36,7 +36,7 @@ public GraphQLArgumentsAttribute(string argumentName, string argumentType, strin
}

/// <summary>
/// Initilizes a attribute which defines a argument which is used for a GraphQL field
/// Initializes a attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand All @@ -53,7 +53,7 @@ public GraphQLArgumentsAttribute(string argumentName, string argumentType, strin
}

/// <summary>
/// Initilizes a attribute which defines a argument which is used for a GraphQL field
/// Initializes a attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLFieldNameAttribute : Attribute
{
/// <summary>
/// Initilizes a attribute which defines the current property or class should map to a specific GraphQL field name
/// Initializes a attribute which defines the current property or class should map to a specific GraphQL field name
/// </summary>
/// <param name="fieldName">The GraphQL field</param>
public GraphQLFieldNameAttribute(string fieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLFirstArgumentsAttribute : GraphQLArgumentsAttribute
{
/// <summary>
/// Initilizes the first argument attribute using the argumentName "first" and the argumentType "Int"
/// Initializes the first argument attribute using the argumentName "first" and the argumentType "Int"
/// </summary>
/// <param name="variableName">The variable name to use in the query</param>
public GraphQLFirstArgumentsAttribute(string variableName) : base("first", "Int", variableName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLLastArgumentsAttribute : GraphQLArgumentsAttribute
{
/// <summary>
/// Initilizes the last argument attribute using the argumentName "last" and the argumentType "Int"
/// Initializes the last argument attribute using the argumentName "last" and the argumentType "Int"
/// </summary>
/// <param name="variableName">The variable name to use in the query</param>
public GraphQLLastArgumentsAttribute(string variableName) : base("last", "Int", variableName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLSkipArgumentsAttribute : GraphQLArgumentsAttribute
{
/// <summary>
/// Initilizes the skip argument attribute using the argumentName "skip" and the argumentType "Int"
/// Initializes the skip argument attribute using the argumentName "skip" and the argumentType "Int"
/// </summary>
/// <param name="variableName">The variable name to use in the query</param>
public GraphQLSkipArgumentsAttribute(string variableName) : base("skip", "Int", variableName)
{
}

/// <summary>
/// Initilizes a skip argument attribute which defines a argument which is used for a GraphQL field
/// Initializes a skip argument attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace SAHB.GraphQLClient.FieldBuilder.Attributes
public class GraphQLTakeArgumentsAttribute : GraphQLArgumentsAttribute
{
/// <summary>
/// Initilizes the take argument attribute using the argumentName "take" and the argumentType "Int"
/// Initializes the take argument attribute using the argumentName "take" and the argumentType "Int"
/// </summary>
/// <param name="variableName">The variable name to use in the query</param>
public GraphQLTakeArgumentsAttribute(string variableName) : base("take", "Int", variableName)
{
}

/// <summary>
/// Initilizes a take argument attribute which defines a argument which is used for a GraphQL field
/// Initializes a take argument attribute which defines a argument which is used for a GraphQL field
/// </summary>
/// <param name="argumentName">The argument name used in the GraphQL query</param>
/// <param name="argumentType">The argument type of the argument in the GraphQL query</param>
Expand Down
2 changes: 1 addition & 1 deletion src/SAHB.GraphQLClient/FieldBuilder/GraphQLField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SAHB.GraphQLClient.FieldBuilder
public class GraphQLField
{
/// <summary>
/// Initilizes a GraphQL field used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL field used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="alias">GraphQL alias</param>
/// <param name="field">GraphQL field</param>
Expand Down
12 changes: 6 additions & 6 deletions src/SAHB.GraphQLClient/FieldBuilder/GraphQLFieldArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace SAHB.GraphQLClient.FieldBuilder
public class GraphQLFieldArguments
{
/// <summary>
/// Initilizes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="argument">The argument to initilize from</param>
/// <param name="argument">The argument to initialize from</param>
internal GraphQLFieldArguments(GraphQLArgumentsAttribute argument)
: this(argument.ArgumentName, argument.ArgumentType, argument.VariableName, argument.IsRequired, argument.InlineArgument, argument.DefaultValue)
{
}

/// <summary>
/// Initilizes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="argumentName">GraphQL argument name</param>
/// <param name="argumentType">GraphQL argument type of the variable</param>
Expand All @@ -30,7 +30,7 @@ public GraphQLFieldArguments(string argumentName, string argumentType, string va
}

/// <summary>
/// Initilizes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="argumentName">GraphQL argument name</param>
/// <param name="argumentType">GraphQL argument type of the variable</param>
Expand All @@ -42,7 +42,7 @@ public GraphQLFieldArguments(string argumentName, string argumentType, string va
}

/// <summary>
/// Initilizes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="argumentName">GraphQL argument name</param>
/// <param name="argumentType">GraphQL argument type of the variable</param>
Expand All @@ -58,7 +58,7 @@ public GraphQLFieldArguments(string argumentName, string argumentType, string va
}

/// <summary>
/// Initilizes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// Initializes a GraphQL argument used to contain metadata which can be used for generating a GraphQL query
/// </summary>
/// <param name="argumentName">GraphQL argument name</param>
/// <param name="argumentType">GraphQL argument type of the variable</param>
Expand Down
4 changes: 2 additions & 2 deletions src/SAHB.GraphQLClient/FieldBuilder/GraphQLFieldBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GraphQLFieldBuilder : IGraphQLFieldBuilder
/// <inheritdoc />
public IEnumerable<GraphQLField> GetFields(Type type)
{
// Initilize list with fields and arguments
// Initialize list with fields and arguments
var fields = new List<GraphQLField>();

// Get all properties which has a public get method and can read and write
Expand Down Expand Up @@ -218,7 +218,7 @@ private static bool IsIEnumerableType(Type typeInfo)
/// <summary>
/// Gets type parameter from a the type <param name="typeInfo"></param> which inherits from <see cref="IEnumerable{T}"/>
/// </summary>
/// <returns>Returns the typeparameter from the <see cref="IEnumerable{T}" /></returns>
/// <returns>Returns the type parameter from the <see cref="IEnumerable{T}" /></returns>
private static Type GetIEnumerableType(Type typeInfo)
{
// Check if the type is a array
Expand Down
Loading

0 comments on commit 49dba7e

Please sign in to comment.