X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/EntityGraphQL/Compiler/EntityGraphQLQueryWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private Dictionary<string, ArgType> ProcessVariableDefinitions(OperationDefiniti
var directives = ProcessFieldDirectives(ExecutableDirectiveLocation.VARIABLE_DEFINITION, item.Directives);
foreach (var directive in directives)
{
directive.VisitNode(ExecutableDirectiveLocation.VARIABLE_DEFINITION, schemaProvider, null, new Dictionary<string, object>(), null, null);
directive.VisitNode(ExecutableDirectiveLocation.VARIABLE_DEFINITION, schemaProvider, null, new Dictionary<string, object?>(), null, null);
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ protected override void VisitField(FieldNode node, IGraphQLNode? context)
}
}

public BaseGraphQLQueryField ParseFieldSelect(Expression fieldExp, IField fieldContext, string name, IGraphQLNode context, SelectionSetNode selection, Dictionary<string, object>? arguments)
public BaseGraphQLQueryField ParseFieldSelect(Expression fieldExp, IField fieldContext, string name, IGraphQLNode context, SelectionSetNode selection, Dictionary<string, object?>? arguments)
{
if (fieldContext.ReturnType.IsList)
{
Expand Down Expand Up @@ -317,7 +317,7 @@ private GraphQLListSelectionField BuildDynamicSelectOnCollection(
string resultName,
IGraphQLNode context,
SelectionSetNode selection,
Dictionary<string, object>? arguments
Dictionary<string, object?>? arguments
)
{
if (context == null)
Expand Down Expand Up @@ -346,7 +346,7 @@ private GraphQLObjectProjectionField BuildDynamicSelectForObjectGraph(
IGraphQLNode context,
string name,
SelectionSetNode selection,
Dictionary<string, object>? arguments
Dictionary<string, object?>? arguments
)
{
if (context == null)
Expand All @@ -362,19 +362,17 @@ private GraphQLObjectProjectionField BuildDynamicSelectForObjectGraph(
return graphQLNode;
}

private Dictionary<string, object> ProcessArguments(IField field, IEnumerable<ArgumentNode> queryArguments)
private Dictionary<string, object?> ProcessArguments(IField field, IEnumerable<ArgumentNode> queryArguments)
{
var args = new Dictionary<string, object>();
var args = new Dictionary<string, object?>();
foreach (var arg in queryArguments)
{
var argName = arg.Name.Value;
if (!field.Arguments.ContainsKey(argName))
{
throw new EntityGraphQLCompilerException($"No argument '{argName}' found on field '{field.Name}'");
}
var r = ParseArgument(argName, field, arg);
if (r != null)
args.Add(argName, r);
args.Add(argName, ParseArgument(argName, field, arg));
}
return args;
}
Expand Down Expand Up @@ -415,7 +413,7 @@ private List<GraphQLDirective> ProcessFieldDirectives(ExecutableDirectiveLocatio
if (!processor.Location.Contains(location))
throw new EntityGraphQLCompilerException($"Directive '{directive.Name.Value}' can not be used on '{location}'");
var argTypes = processor.GetArguments(schemaProvider);
var args = new Dictionary<string, object>();
var args = new Dictionary<string, object?>();
foreach (var arg in directive.Arguments)
{
var argVal = ProcessArgumentOrVariable(arg.Name.Value, schemaProvider, arg, argTypes[arg.Name.Value].RawType);
Expand All @@ -441,7 +439,7 @@ protected override void VisitFragmentDefinition(FragmentDefinitionNode node, IGr
{
foreach (var directive in ProcessFieldDirectives(ExecutableDirectiveLocation.FRAGMENT_DEFINITION, node.Directives))
{
directive.VisitNode(ExecutableDirectiveLocation.FRAGMENT_DEFINITION, schemaProvider, fragDef, new Dictionary<string, object>(), null, null);
directive.VisitNode(ExecutableDirectiveLocation.FRAGMENT_DEFINITION, schemaProvider, fragDef, new Dictionary<string, object?>(), null, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static Expression MakePropertyCall(Expression context, ISchemaProvider?
return Expression.Constant(Enum.Parse(schemaType.TypeDotnet, name));
}
var gqlField = schemaType.GetField(name, requestContext);
(var exp, _) = gqlField.GetExpression(gqlField.ResolveExpression!, context, null, null, compileContext, new Dictionary<string, object>(), null, null, [], false, new Util.ParameterReplacer());
(var exp, _) = gqlField.GetExpression(gqlField.ResolveExpression!, context, null, null, compileContext, new Dictionary<string, object?>(), null, null, [], false, new Util.ParameterReplacer());
return exp!;
}

Expand Down
6 changes: 3 additions & 3 deletions src/EntityGraphQL/Compiler/GqlNodes/BaseGraphQLField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class BaseGraphQLField : IGraphQLNode, IFieldKey
/// <summary>
/// Arguments from inline in the query - not $ variables
/// </summary>
public IReadOnlyDictionary<string, object> Arguments { get; }
public IReadOnlyDictionary<string, object?> Arguments { get; }

/// <summary>
/// True if this field directly has services
Expand All @@ -77,14 +77,14 @@ public BaseGraphQLField(
Expression? nextFieldContext,
ParameterExpression? rootParameter,
IGraphQLNode? parentNode,
IReadOnlyDictionary<string, object>? arguments
IReadOnlyDictionary<string, object?>? arguments
)
{
Name = name;
NextFieldContext = nextFieldContext;
RootParameter = rootParameter;
ParentNode = parentNode;
this.Arguments = arguments ?? new Dictionary<string, object>();
this.Arguments = arguments ?? new Dictionary<string, object?>();
this.Schema = schema;
Field = field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected BaseGraphQLQueryField(
Expression? nextFieldContext,
ParameterExpression? rootParameter,
IGraphQLNode? parentNode,
IReadOnlyDictionary<string, object>? arguments
IReadOnlyDictionary<string, object?>? arguments
)
: base(schema, field, name, nextFieldContext, rootParameter, parentNode, arguments) { }

Expand Down
2 changes: 1 addition & 1 deletion src/EntityGraphQL/Compiler/GqlNodes/CompileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ List<IGraphQLNode> listExpressionPath

public void AddArgsToCompileContext(
IField field,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
ParameterExpression? docParam,
object? docVariables,
ref object? argumentValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class ExecutableGraphQLStatement : IGraphQLNode
public IField? Field { get; }
public bool HasServices => Field?.Services.Count > 0;

public IReadOnlyDictionary<string, object> Arguments { get; }
public IReadOnlyDictionary<string, object?> Arguments { get; }

public string? Name { get; }

Expand All @@ -52,7 +52,7 @@ public ExecutableGraphQLStatement(ISchemaProvider schema, string? name, Expressi
RootParameter = rootParameter;
OpDefinedVariables = opVariables;
this.Schema = schema;
Arguments = new Dictionary<string, object>();
Arguments = new Dictionary<string, object?>();
if (OpDefinedVariables.Count > 0)
{
var variableType = LinqRuntimeTypeBuilder.GetDynamicType(OpDefinedVariables.ToDictionary(f => f.Key, f => f.Value.RawType), "docVars");
Expand Down
8 changes: 4 additions & 4 deletions src/EntityGraphQL/Compiler/GqlNodes/GraphQLDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace EntityGraphQL.Compiler;
public class GraphQLDirective
{
private readonly IDirectiveProcessor processor;
private readonly Dictionary<string, object> inlineArgValues;
private readonly Dictionary<string, object?> inlineArgValues;
private readonly string name;

public GraphQLDirective(string name, IDirectiveProcessor processor, Dictionary<string, object> inlineArgValues)
public GraphQLDirective(string name, IDirectiveProcessor processor, Dictionary<string, object?> inlineArgValues)
{
this.processor = processor;
this.inlineArgValues = inlineArgValues;
Expand All @@ -23,7 +23,7 @@ public GraphQLDirective(string name, IDirectiveProcessor processor, Dictionary<s
ExecutableDirectiveLocation location,
ISchemaProvider schema,
IGraphQLNode? node,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
ParameterExpression? docParam,
object? docVariables
)
Expand All @@ -33,7 +33,7 @@ public GraphQLDirective(string name, IDirectiveProcessor processor, Dictionary<s
schema,
name,
null,
inlineArgValues.MergeNew(args),
inlineArgValues.MergeNewNullable(args),
processor.GetArguments(schema).Values,
processor.GetArgumentsType(),
docParam,
Expand Down
4 changes: 2 additions & 2 deletions src/EntityGraphQL/Compiler/GqlNodes/GraphQLDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public GraphQLDocument(ISchemaProvider schema)
Schema = schema;
Operations = [];
Fragments = [];
Arguments = new Dictionary<string, object>();
Arguments = new Dictionary<string, object?>();
}

public string Name => "Query Request Root";

public IField? Field { get; }
public bool HasServices => Field?.Services.Count > 0;

public IReadOnlyDictionary<string, object> Arguments { get; }
public IReadOnlyDictionary<string, object?> Arguments { get; }

public ISchemaProvider Schema { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GraphQLFragmentStatement : IGraphQLNode
public IField? Field { get; }
public bool HasServices => Field?.Services.Count > 0;

public IReadOnlyDictionary<string, object> Arguments { get; }
public IReadOnlyDictionary<string, object?> Arguments { get; }

public string Name { get; }

Expand All @@ -28,7 +28,7 @@ public GraphQLFragmentStatement(ISchemaProvider schema, string name, ParameterEx
Name = name;
NextFieldContext = selectContext;
RootParameter = rootParameter;
Arguments = new Dictionary<string, object>();
Arguments = new Dictionary<string, object?>();
Schema = schema;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GraphQLListSelectionField(
ParameterExpression? rootParameter,
Expression nodeExpression,
IGraphQLNode context,
Dictionary<string, object>? arguments
Dictionary<string, object?>? arguments
)
: base(schema, field, name, nextFieldContext, rootParameter, context, arguments)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GraphQLMutationField(
ISchemaProvider schema,
string name,
MutationField mutationField,
Dictionary<string, object>? args,
Dictionary<string, object?>? args,
Expression nextFieldContext,
ParameterExpression rootParameter,
IGraphQLNode parentNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public GraphQLObjectProjectionField(
Expression nextFieldContext,
ParameterExpression rootParameter,
IGraphQLNode parentNode,
IReadOnlyDictionary<string, object>? arguments
IReadOnlyDictionary<string, object?>? arguments
)
: base(schema, field, name, nextFieldContext, rootParameter, parentNode, arguments) { }

Expand Down
2 changes: 1 addition & 1 deletion src/EntityGraphQL/Compiler/GqlNodes/GraphQLScalarField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public GraphQLScalarField(
Expression nextFieldContext,
ParameterExpression? rootParameter,
IGraphQLNode parentNode,
IReadOnlyDictionary<string, object>? arguments
IReadOnlyDictionary<string, object?>? arguments
)
: base(schema, field, name, nextFieldContext, rootParameter, parentNode, arguments) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GraphQLSubscriptionField(
ISchemaProvider schema,
string name,
SubscriptionField subscriptionField,
Dictionary<string, object>? args,
Dictionary<string, object?>? args,
Expression nextFieldContext,
ParameterExpression rootParameter,
IGraphQLNode parentNode
Expand Down
2 changes: 1 addition & 1 deletion src/EntityGraphQL/Compiler/GqlNodes/IGraphQLNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IGraphQLNode
void AddField(BaseGraphQLField field);
IField? Field { get; }
bool HasServices { get; }
IReadOnlyDictionary<string, object> Arguments { get; }
IReadOnlyDictionary<string, object?> Arguments { get; }
void AddDirectives(IEnumerable<GraphQLDirective> graphQLDirectives);

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/EntityGraphQL/Compiler/Util/ArgumentUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class ArgumentUtil
ISchemaProvider schema,
string fieldName,
IField? field,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
IEnumerable<ArgType> argumentDefinitions,
Type? argumentsType,
ParameterExpression? docParam,
Expand Down Expand Up @@ -122,7 +122,7 @@ private static void SetArgumentValues(Dictionary<string, object?> values, object

internal static object? BuildArgumentFromMember(
ISchemaProvider schema,
IReadOnlyDictionary<string, object>? args,
IReadOnlyDictionary<string, object?>? args,
string memberName,
Type memberType,
object? defaultValue,
Expand All @@ -139,6 +139,10 @@ IList<string> validationErrors
return null;
}
var item = args[argName];
if(item is null)
{
return null;
}
var constructor = memberType.GetConstructor(new[] { item.GetType() });
if (constructor == null)
{
Expand Down
11 changes: 11 additions & 0 deletions src/EntityGraphQL/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ public static Dictionary<TKey, TElement> MergeNew<TKey, TElement>(this IDictiona

return result;
}

public static Dictionary<TKey, TElement?> MergeNewNullable<TKey, TElement>(this IDictionary<TKey, TElement?> source, IReadOnlyDictionary<TKey, TElement?>? other)
where TKey : notnull
{
var result = source != null ? source.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) : [];
if (other != null)
foreach (var kvp in other)
result[kvp.Key] = kvp.Value;

return result;
}
}
2 changes: 1 addition & 1 deletion src/EntityGraphQL/Schema/BaseField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public abstract (Expression? expression, ParameterExpression? argumentParam) Get
IGraphQLNode? parentNode,
ParameterExpression? schemaContext,
CompileContext compileContext,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
ParameterExpression? docParam,
object? docVariables,
IEnumerable<GraphQLDirective> directives,
Expand Down
4 changes: 2 additions & 2 deletions src/EntityGraphQL/Schema/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public override (Expression? expression, ParameterExpression? argumentParam) Get
IGraphQLNode? parentNode,
ParameterExpression? schemaContext,
CompileContext compileContext,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
ParameterExpression? docParam,
object? docVariables,
IEnumerable<GraphQLDirective> directives,
Expand Down Expand Up @@ -196,7 +196,7 @@ ParameterReplacer replacer
}

private (Expression? fieldExpression, ParameterExpression? argumentParam) PrepareFieldExpression(
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
Expression fieldExpression,
ParameterReplacer replacer,
Expression context,
Expand Down
2 changes: 1 addition & 1 deletion src/EntityGraphQL/Schema/IField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public interface IField
IGraphQLNode? parentNode,
ParameterExpression? schemaContext,
CompileContext compileContext,
IReadOnlyDictionary<string, object> args,
IReadOnlyDictionary<string, object?> args,
ParameterExpression? docParam,
object? docVariables,
IEnumerable<GraphQLDirective> directives,
Expand Down
Loading
X Tutup