private static Field ProcessFieldOrProperty(MemberInfo prop, Type fieldOrPropType, ParameterExpression param, ISchemaProvider schema, bool createEnumTypes, bool createNewComplexTypes) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return(null); } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var attributes = prop.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute), true).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(attributes); var returnType = le.ReturnType.IsEnumerableOrArray() ? le.ReturnType.GetEnumerableOrArrayType() : le.ReturnType; var t = CacheType(returnType, schema, createEnumTypes, createNewComplexTypes); var f = new Field(SchemaGenerator.ToCamelCaseStartsLower(prop.Name), le, description, null, null, requiredClaims); if (t != null && t.IsEnum && !f.ReturnTypeClr.IsNullableType()) { f.ReturnTypeNotNullable = true; } return(f); }
public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync) { Description = description; ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; this.isAsync = isAsync; argInstanceType = method.GetParameters() .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType; if (argInstanceType != null) { foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromProperty(schema, item)); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromField(schema, item)); } } }
/// <summary> /// Build INPUT Type to be used by Mutations /// </summary> /// <param name="schema"></param> /// <remarks> /// Since Types and Inputs cannot have the same name, camelCase the name to prevent duplicates. /// </remarks> /// <returns></returns> private static List <TypeElement> BuildInputTypes(ISchemaProvider schema) { var types = new List <TypeElement>(); foreach (ISchemaType schemaType in schema.GetNonContextTypes().Where(s => s.IsInput)) { if (schemaType.Name.StartsWith("__")) { continue; } var inputValues = new List <InputValue>(); foreach (Field field in schemaType.GetFields()) { if (field.Name.StartsWith("__")) { continue; } // Skip any property with special attribute //== JT: When reading PropertyInfo, must use the default casing. Had to convert back to Pascal from Camel case var property = schemaType.ContextType.GetProperty(SchemaGenerator.ToPascalCaseStartsUpper(field.Name)); if (property != null && GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(property)) { continue; } // Skipping custom fields added to schema if (field.Resolve.NodeType == System.Linq.Expressions.ExpressionType.Call) { continue; } // Skipping ENUM type if (field.ReturnType.TypeDotnet.GetTypeInfo().IsEnum) { continue; } inputValues.Add(new InputValue { Name = field.Name, Description = field.Description, Type = BuildType(schema, field.ReturnType, field.ReturnType.TypeDotnet, true) }); } var typeElement = new TypeElement { Kind = "INPUT_OBJECT", Name = schemaType.Name, Description = schemaType.Description, InputFields = inputValues.ToArray() }; types.Add(typeElement); } return(types); }
private static Field ProcessFieldOrProperty <TContextType>(MemberInfo prop, Type fieldOrPropType, ParameterExpression param, MappedSchemaProvider <TContextType> schema) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return(null); } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var f = new Field(SchemaGenerator.ToCamelCaseStartsLower(prop.Name), le, description); var t = CacheType <TContextType>(fieldOrPropType, schema); if (t != null && t.IsEnum && !f.ReturnTypeClr.IsNullableType()) { f.ReturnTypeNotNullable = true; } return(f); }
/// <summary> /// Add any methods marked with GraphQLMutationAttribute in the given type to the schema. Names are added as lowerCaseCamel` /// </summary> /// <param name="mutationClassInstance"></param> /// <typeparam name="TType"></typeparam> public void AddMutationFrom <TType>(TType mutationClassInstance) { foreach (var method in mutationClassInstance.GetType().GetMethods()) { if (method.GetCustomAttribute(typeof(GraphQLMutationAttribute)) is GraphQLMutationAttribute attribute) { var isAsync = method.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null; string name = SchemaGenerator.ToCamelCaseStartsLower(method.Name); //== JT: Allow user to customize the schema-first casing. var n = (System.ComponentModel.DisplayNameAttribute)method.GetCustomAttribute(typeof(System.ComponentModel.DisplayNameAttribute), false); if (n != null) { name = n.DisplayName; } //== var claims = method.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute)).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(claims); var actualReturnType = GetTypeFromMutationReturn(isAsync ? method.ReturnType.GetGenericArguments()[0] : method.ReturnType); var typeName = GetSchemaTypeNameForDotnetType(actualReturnType); var returnType = new GqlTypeInfo(() => GetReturnType(typeName), actualReturnType); var mutationType = new MutationType(this, name, returnType, mutationClassInstance, method, attribute.Description, requiredClaims, isAsync, SchemaFieldNamer); mutations[name] = mutationType; } } }
public Field ReplaceField <TParams, TReturn>(Expression <Func <TContextType, object> > selection, TParams argTypes, Expression <Func <TContextType, TParams, TReturn> > selectionExpression, string description, string returnSchemaType = null, bool?isNullable = null) { var exp = ExpressionUtil.CheckAndGetMemberExpression(selection); var name = SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name); Type <TContextType>().RemoveField(name); return(Type <TContextType>().AddField(name, argTypes, selectionExpression, description, returnSchemaType, isNullable)); }
public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync, Func <MemberInfo, string> fieldNamer) { Description = description; ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; this.isAsync = isAsync; argInstanceType = method.GetParameters() .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType; if (argInstanceType != null) { foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(fieldNamer(item), ArgType.FromProperty(schema, item)); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(fieldNamer(item), ArgType.FromField(schema, item)); } } //== JT: Start Here else { /*== JT * When parameters are the standard System Types like; Int, String, etc or using the EntityGraphQL.Schema.RequiredField, * loop through the parameters and NOT the object's properties * NOTE: some parameters might be Services * EX: public ReturnModel RemoveById(DataContext context, RequiredField<int> id) */ // !! Forcing a single parameter ONLY. Anything more than that should require a POCO !! ParameterInfo item = method.GetParameters() .FirstOrDefault(p => p.ParameterType.Namespace.StartsWith("EntityGraphQL.Schema") || p.ParameterType.Namespace.StartsWith("System")); if (item.ParameterType.Name == "Nullable`1") { Type argType = item.ParameterType.GetGenericArguments()[0]; argInstanceType = argType; } else { argInstanceType = item.ParameterType; } //TODO: see if able to use the "fieldNamer()" function argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromParameter(schema, item)); } //== }
/// <summary> /// Add any methods marked with GraphQLMutationAttribute in the given type to the schema. Names are added as lowerCaseCamel` /// </summary> /// <param name="mutationClassInstance"></param> /// <typeparam name="TType"></typeparam> public void AddMutationFrom <TType>(TType mutationClassInstance) { foreach (var method in mutationClassInstance.GetType().GetMethods()) { var attribute = method.GetCustomAttribute(typeof(GraphQLMutationAttribute)) as GraphQLMutationAttribute; if (attribute != null) { string name = SchemaGenerator.ToCamelCaseStartsLower(method.Name); var mutationType = new MutationType(name, types[GetSchemaTypeNameForRealType(method.ReturnType)], mutationClassInstance, method, attribute.Description); mutations[name] = mutationType; } } }
private static TypeElement BuildType(ISchemaProvider schema, GqlTypeInfo typeInfo, Type clrType, bool isInput = false) { // Is collection of objects? var type = new TypeElement(); if (clrType.IsEnumerableOrArray()) { type.Kind = "LIST"; type.Name = null; type.OfType = BuildType(schema, typeInfo, clrType.GetEnumerableOrArrayType(), isInput); } else if (clrType.Name == "EntityQueryType`1") { type.Kind = "SCALAR"; type.Name = "String"; type.OfType = null; } else if (clrType.GetTypeInfo().IsEnum) { type.Kind = "ENUM"; type.Name = typeInfo.SchemaType.Name; type.OfType = null; } else { type.Kind = typeInfo.SchemaType.IsScalar ? "SCALAR" : "OBJECT"; type.OfType = null; if (type.Kind == "OBJECT" && isInput) { type.Kind = "INPUT_OBJECT"; //== JT: !! INPUT_OBJECT names MUST use camelCase to avoid collision to OBJECT types !! type.Name = SchemaGenerator.ToCamelCaseStartsLower(typeInfo.SchemaType.Name); } else { type.Name = typeInfo.SchemaType.Name; } //== } if (typeInfo.TypeNotNullable) { return(new TypeElement { Kind = "NON_NULL", Name = null, OfType = type }); } return(type); }
/// <summary> /// Add any methods marked with GraphQLMutationAttribute in the given type to the schema. Names are added as lowerCaseCamel` /// </summary> /// <param name="mutationClassInstance"></param> /// <typeparam name="TType"></typeparam> public void AddMutationFrom <TType>(TType mutationClassInstance) { foreach (var method in mutationClassInstance.GetType().GetMethods()) { if (method.GetCustomAttribute(typeof(GraphQLMutationAttribute)) is GraphQLMutationAttribute attribute) { string name = SchemaGenerator.ToCamelCaseStartsLower(method.Name); var claims = method.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute)).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(claims); var mutationType = new MutationType(name, types[GetSchemaTypeNameForClrType(method.ReturnType)], mutationClassInstance, method, attribute.Description, requiredClaims); mutations[name] = mutationType; } } }
/// <summary> /// Add any methods marked with GraphQLMutationAttribute in the given type to the schema. Names are added as lowerCaseCamel` /// </summary> /// <param name="mutationClassInstance"></param> /// <typeparam name="TType"></typeparam> public void AddMutationFrom <TType>(TType mutationClassInstance) { foreach (var method in mutationClassInstance.GetType().GetMethods()) { if (method.GetCustomAttribute(typeof(GraphQLMutationAttribute)) is GraphQLMutationAttribute attribute) { var isAsync = method.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null; string name = SchemaGenerator.ToCamelCaseStartsLower(method.Name); var claims = method.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute)).Cast <GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(claims); var actualReturnType = GetTypeFromMutationReturn(isAsync ? method.ReturnType.GetGenericArguments()[0] : method.ReturnType); var typeName = GetSchemaTypeNameForDotnetType(actualReturnType); var returnType = new GqlTypeInfo(() => GetReturnType(typeName), actualReturnType); var mutationType = new MutationType(this, name, returnType, mutationClassInstance, method, attribute.Description, requiredClaims, isAsync); mutations[name] = mutationType; } } }
private void BuildFieldsFromBase() { if (IsEnum) { foreach (var item in Enum.GetNames(this.ContextType)) { this.AddField(new Field(item, null, "", Name, ContextType)); } return; } foreach (var f in ContextType.GetProperties()) { if (!_fieldsByName.ContainsKey(f.Name)) { //Get Description from ComponentModel.DescriptionAttribute string description = string.Empty; var d = (System.ComponentModel.DescriptionAttribute)f.GetCustomAttribute(typeof(System.ComponentModel.DescriptionAttribute), false); if (d != null) { description = d.Description; } var parameter = Expression.Parameter(ContextType); this.AddField(new Field(SchemaGenerator.ToCamelCaseStartsLower(f.Name), Expression.Lambda(Expression.Property(parameter, f.Name), parameter), description, null)); } } foreach (var f in ContextType.GetFields()) { if (!_fieldsByName.ContainsKey(f.Name)) { //Get Description from ComponentModel.DescriptionAttribute string description = string.Empty; var d = (System.ComponentModel.DescriptionAttribute)f.GetCustomAttribute(typeof(System.ComponentModel.DescriptionAttribute), false); if (d != null) { description = d.Description; } var parameter = Expression.Parameter(ContextType); this.AddField(new Field(SchemaGenerator.ToCamelCaseStartsLower(f.Name), Expression.Lambda(Expression.Field(parameter, f.Name), parameter), description, null)); } } }
private static TypeElement BuildType(ISchemaProvider schema, Type clrType, string gqlTypeName, IReadOnlyDictionary <Type, string> combinedMapping, bool isInput = false) { // Is collection of objects? var type = new TypeElement(); if (clrType.IsEnumerableOrArray()) { type.Kind = "LIST"; type.Name = null; type.OfType = BuildType(schema, clrType.GetEnumerableOrArrayType(), gqlTypeName, combinedMapping, isInput); } else if (clrType.Name == "RequiredField`1") { type.Kind = "NON_NULL"; type.Name = null; type.OfType = BuildType(schema, clrType.GetGenericArguments()[0], gqlTypeName, combinedMapping, isInput); } else if (clrType.GetTypeInfo().IsEnum) { type.Kind = "ENUM"; type.Name = FindNamedMapping(clrType, combinedMapping, gqlTypeName); type.OfType = null; } else { type.Kind = FindTypeInMapping(clrType, combinedMapping) != null ? "SCALAR" : "OBJECT"; type.OfType = null; if (type.Kind == "OBJECT" && isInput) { type.Name = SchemaGenerator.ToCamelCaseStartsLower(FindNamedMapping(clrType, combinedMapping, gqlTypeName)); } else { type.Name = FindNamedMapping(clrType, combinedMapping, gqlTypeName); } } return(type); }
private object AssignArgValues(Dictionary <string, ExpressionResult> gqlRequestArgs) { var argInstance = Activator.CreateInstance(this.argInstanceType); Type argType = this.argInstanceType; foreach (var key in gqlRequestArgs.Keys) { var foundProp = false; foreach (var prop in argType.GetProperties()) { var propName = SchemaGenerator.ToCamelCaseStartsLower(prop.Name); if (key == propName) { object value = GetValue(gqlRequestArgs, propName, prop.PropertyType); prop.SetValue(argInstance, value); foundProp = true; } } if (!foundProp) { foreach (var field in argType.GetFields()) { var fieldName = SchemaGenerator.ToCamelCaseStartsLower(field.Name); if (key == fieldName) { object value = GetValue(gqlRequestArgs, fieldName, field.FieldType); field.SetValue(argInstance, value); foundProp = true; } } } if (!foundProp) { throw new EntityQuerySchemaException($"Could not find property or field {key} on schema object {argType.Name}"); } } return(argInstance); }
/// <summary> /// This is used in a lazy evaluated field as a graph can have circular dependencies /// </summary> /// <param name="schema"></param> /// <param name="combinedMapping"></param> /// <param name="typeName"></param> /// <returns></returns> public static Models.Field[] BuildFieldsForType(ISchemaProvider schema, string typeName) { if (typeName == "Query") { return(BuildRootQueryFields(schema)); } if (typeName == "Mutation") { return(BuildMutationFields(schema)); } var fieldDescs = new List <Models.Field>(); if (!schema.HasType(typeName)) { return(fieldDescs.ToArray()); } var type = schema.Type(typeName); foreach (var field in type.GetFields()) { if (field.Name.StartsWith("__")) { continue; } fieldDescs.Add(new Models.Field { Args = BuildArgs(schema, field).ToArray(), DeprecationReason = "", Description = field.Description, IsDeprecated = false, Name = SchemaGenerator.ToCamelCaseStartsLower(field.Name), Type = BuildType(schema, field.ReturnType, field.ReturnType.TypeDotnet), }); } return(fieldDescs.ToArray()); }
public MutationType(string methodName, ISchemaType returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims) { this.Description = description; this.ReturnType = returnType; this.mutationClassInstance = mutationClassInstance; this.method = method; Name = methodName; AuthorizeClaims = authorizeClaims; var methodArg = method.GetParameters().ElementAt(1); this.argInstanceType = methodArg.ParameterType; foreach (var item in argInstanceType.GetProperties()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType { Type = item.PropertyType, TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.PropertyType.GetTypeInfo().IsEnum }); } foreach (var item in argInstanceType.GetFields()) { if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item)) { continue; } argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), new ArgType { Type = item.FieldType, TypeNotNullable = GraphQLNotNullAttribute.IsMemberMarkedNotNull(item) || item.FieldType.GetTypeInfo().IsEnum }); } }
private static Field ProcessFieldOrProperty(MemberInfo prop, ParameterExpression param, ISchemaProvider schema, bool createEnumTypes, bool createNewComplexTypes, Func<MemberInfo, string> fieldNamer) { if (ignoreProps.Contains(prop.Name) || GraphQLIgnoreAttribute.ShouldIgnoreMemberFromQuery(prop)) { return null; } // Get Description from ComponentModel.DescriptionAttribute string description = ""; var d = (DescriptionAttribute)prop.GetCustomAttribute(typeof(DescriptionAttribute), false); if (d != null) { description = d.Description; } LambdaExpression le = Expression.Lambda(prop.MemberType == MemberTypes.Property ? Expression.Property(param, prop.Name) : Expression.Field(param, prop.Name), param); var attributes = prop.GetCustomAttributes(typeof(GraphQLAuthorizeAttribute), true).Cast<GraphQLAuthorizeAttribute>(); var requiredClaims = new RequiredClaims(attributes); // get the object type returned (ignoring list etc) so we know the context to find fields etc var returnType = le.ReturnType.IsEnumerableOrArray() ? le.ReturnType.GetEnumerableOrArrayType() : le.ReturnType.GetNonNullableType(); var t = CacheType(returnType, schema, createEnumTypes, createNewComplexTypes, fieldNamer); // see if there is a direct type mapping from the expression return to to something. // otherwise build the type info var returnTypeInfo = schema.GetCustomTypeMapping(le.ReturnType) ?? new GqlTypeInfo(() => schema.Type(returnType), le.Body.Type); /*== JT * Allow user to customize the schema-first casing. */ string propName = SchemaGenerator.ToCamelCaseStartsLower(prop.Name); var n = (DisplayNameAttribute)prop.GetCustomAttribute(typeof(DisplayNameAttribute), false); if (n != null) propName = n.DisplayName; //== // TODO: Luke added a `fieldNamer()`, need to review before adding propName variable var f = new Field(fieldNamer(prop), le, description, returnTypeInfo, requiredClaims); return f; }
/// <summary> /// Remove a field by an expression selection on the real type. The name is changed to lowerCaseCamel /// </summary> /// <param name="fieldSelection"></param> public void RemoveField(Expression <Func <TBaseType, object> > fieldSelection) { var exp = ExpressionUtil.CheckAndGetMemberExpression(fieldSelection); RemoveField(SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name)); }
private object AssignArgValues(Dictionary <string, ExpressionResult> gqlRequestArgs) { //== JT: "No parameterless constructor defined for type 'System.String'." object argInstance; if (this.argInstanceType.Name == "String") { argInstance = Activator.CreateInstance(this.argInstanceType, new char[] { }); } else { argInstance = Activator.CreateInstance(this.argInstanceType); } Type argType = this.argInstanceType; /*== JT: When using single parameter in a mutation, * EX: public ReturnObj MethodName(DataContext context, RequiredField<int> id) { } */ if (argType.Name == "RequiredField`1") { var prop = argInstance.GetType().GetProperty("Value"); string memberName = gqlRequestArgs.First().Key; object value = GetValue(gqlRequestArgs, memberName, prop.PropertyType); prop.SetValue(argInstance, value); return(argInstance); } else if (argType.Namespace.StartsWith("System")) { string memberName = gqlRequestArgs.First().Key; object value = Expression.Lambda(gqlRequestArgs[memberName]).Compile().DynamicInvoke(); value = Convert.ChangeType(value, argType); //assign value directly argInstance = value; return(argInstance); } //== foreach (var key in gqlRequestArgs.Keys) { var foundProp = false; foreach (var prop in argType.GetProperties()) { var propName = SchemaGenerator.ToCamelCaseStartsLower(prop.Name); if (key == propName) { object value = GetValue(gqlRequestArgs, propName, prop.PropertyType); prop.SetValue(argInstance, value); foundProp = true; } } if (!foundProp) { foreach (var field in argType.GetFields()) { var fieldName = SchemaGenerator.ToCamelCaseStartsLower(field.Name); if (key == fieldName) { object value = GetValue(gqlRequestArgs, fieldName, field.FieldType); field.SetValue(argInstance, value); foundProp = true; } } } if (!foundProp) { throw new EntityQuerySchemaException($"Could not find property or field {key} on schema object {argType.Name}"); } } return(argInstance); }
/// <summary> /// Add a field from a type expression. The name to converted to lowerCamelCase /// </summary> /// <param name="fieldSelection"></param> /// <param name="description"></param> /// <param name="returnSchemaType"></param> /// <typeparam name="TReturn"></typeparam> public Field AddField <TReturn>(Expression <Func <TBaseType, TReturn> > fieldSelection, string description, string returnSchemaType = null, bool?isNullable = null, RequiredClaims authorizeClaims = null) { var exp = ExpressionUtil.CheckAndGetMemberExpression(fieldSelection); return(AddField(SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name), fieldSelection, description, returnSchemaType, isNullable, authorizeClaims)); }
/// <summary> /// Add a field to the root type. This is where you define top level objects/names that you can query. /// The name defaults to the MemberExpression from selection modified to lowerCamelCase /// </summary> /// <param name="selection"></param> /// <param name="description"></param> /// <param name="returnSchemaType"></param> public Field AddField(Expression <Func <TContextType, object> > selection, string description, string returnSchemaType = null, bool?isNullable = null) { var exp = ExpressionUtil.CheckAndGetMemberExpression(selection); return(AddField(SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name), selection, description, returnSchemaType, isNullable)); }
/// <summary> /// Add a field from a type expression. The name to converted to lowerCamelCase /// </summary> /// <param name="fieldSelection"></param> /// <param name="description"></param> /// <param name="returnSchemaType"></param> /// <typeparam name="TReturn"></typeparam> public Field AddField <TReturn>(Expression <Func <TBaseType, TReturn> > fieldSelection, string description, string returnSchemaType = null) { var exp = ExpressionUtil.CheckAndGetMemberExpression(fieldSelection); return(AddField(SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name), fieldSelection, description, returnSchemaType)); }
/// <summary> /// Builds a GraphQL schema file /// </summary> /// <returns></returns> public string GetGraphQLSchema() { var extraMappings = customTypeMappings.ToDictionary(k => k.Key, v => v.Value); return(SchemaGenerator.Make(this, extraMappings, this.customScalarTypes)); }
/// <summary> /// Get a field by an expression selection on the real type. The name is changed to lowerCaseCamel /// </summary> /// <param name="fieldSelection"></param> public Field GetField(Expression <Func <TBaseType, object> > fieldSelection, ClaimsIdentity claims = null) { var exp = ExpressionUtil.CheckAndGetMemberExpression(fieldSelection); return(GetField(SchemaGenerator.ToCamelCaseStartsLower(exp.Member.Name), claims)); }