Skip to content

Commit

Permalink
Fixes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
sahb1239 committed Sep 5, 2018
1 parent 1831179 commit 1cafcad
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ private string GetQuery(string queryType, ICollection<GraphQLField> fields, para
{
// Get all the arguments from the fields
var fieldArguments = Helper.GetAllArgumentsFromFields(fields).ToList();


// Create list of argument variables which was not found
var variablesNotFoundInFields = queryArguments.ToList();

// Create mapping for each argument field
IDictionary<GraphQLFieldArguments, GraphQLQueryArgument> arguments = new Dictionary<GraphQLFieldArguments, GraphQLQueryArgument>();
ICollection<GraphQLFieldArguments> argumentsNotSet = new Collection<GraphQLFieldArguments>();
List<string> duplicateVariableNames = new List<string>();
foreach (var fieldArgument in fieldArguments)
{
// Remove from variablesNotFoundInFields
variablesNotFoundInFields.RemoveAll(argument => argument.VariableName == fieldArgument.VariableName);

// Find matching query arguments
var queryArgument = queryArguments.Where(e => e.VariableName == fieldArgument.VariableName).Take(2).ToList();

// Find match for argument
switch (queryArgument.Count)
{
case 0:
Expand Down Expand Up @@ -77,6 +84,12 @@ private string GetQuery(string queryType, ICollection<GraphQLField> fields, para
throw new GraphQLDuplicateVariablesException(duplicateVariableNames);
}

// Check if any supplied arguments was not found in fields
if (variablesNotFoundInFields.Any())
{
throw new GraphQLArgumentVariableNotFoundException(variablesNotFoundInFields);
}

// Get readonly arguments
var readonlyArguments = new ReadOnlyDictionary<GraphQLFieldArguments, GraphQLQueryArgument>(arguments);

Expand Down

0 comments on commit 1cafcad

Please sign in to comment.