private static void AddSerializerToInputField(
            ITypeCompletionContext completionContext,
            ArgumentDefinition definition,
            NameString typeName)
        {
            ITypeInspector typeInspector = completionContext.TypeInspector;
            IExtendedType? resultType;

            if (definition is InputFieldDefinition inputField)
            {
                resultType = typeInspector.GetReturnType(inputField.Property, true);
            }
            else if (definition.Parameter is not null)
            {
                resultType = typeInspector.GetArgumentType(definition.Parameter, true);
            }
            else if (definition.Type is ExtendedTypeReference typeReference)
            {
                resultType = typeReference.Type;
            }
            else
            {
                throw new SchemaException(SchemaErrorBuilder.New()
                                          .SetMessage("Unable to resolve type from field `{0}`.", definition.Name)
                                          .SetTypeSystemObject(completionContext.Type)
                                          .Build());
            }

            definition.Formatters.Add(CreateSerializer(completionContext, resultType, typeName));
        }
 protected QueryableSpatialMethodHandler(
     IFilterConvention convention,
     ITypeInspector inspector,
     MethodInfo method)
 {
     _runtimeType      = inspector.GetReturnType(method);
     GeometryFieldName = convention.GetOperationName(SpatialFilterOperations.Geometry);
     BufferFieldName   = convention.GetOperationName(SpatialFilterOperations.Buffer);
 }
示例#3
0
        private static (string NodeTypeName, Type IdRuntimeType)? GetIdInfo(
            ITypeCompletionContext completionContext,
            ArgumentDefinition definition)
        {
            ITypeInspector typeInspector = completionContext.TypeInspector;
            IDAttribute?   idAttribute   = null;
            IExtendedType? idType        = null;

            if (definition is InputFieldDefinition inputField)
            {
                idAttribute = (IDAttribute?)inputField.Property
                              .GetCustomAttributes(inherit: true)
                              .SingleOrDefault(a => a is IDAttribute);
                if (idAttribute == null)
                {
                    return(null);
                }

                idType = typeInspector.GetReturnType(inputField.Property, true);
            }
            else if (definition.Parameter is not null)
            {
                idAttribute = (IDAttribute?)definition.Parameter
                              .GetCustomAttributes(inherit: true)
                              .SingleOrDefault(a => a is IDAttribute);
                if (idAttribute == null)
                {
                    return(null);
                }

                idType = typeInspector.GetArgumentType(definition.Parameter, true);
            }
            else if (definition.Type is ExtendedTypeReference typeReference)
            {
                if (typeReference.Type.Kind == ExtendedTypeKind.Schema)
                {
                    return(null);
                }
            }

            if (idAttribute is null || idType is null)
            {
                throw new SchemaException(SchemaErrorBuilder.New()
                                          .SetMessage("Unable to resolve type from field `{0}`.", definition.Name)
                                          .SetTypeSystemObject(completionContext.Type)
                                          .Build());
            }

            Type   idRuntimeType = idType.ElementType?.Source ?? idType.Source;
            string nodeTypeName  = idAttribute?.TypeName.HasValue ?? false
                ? idAttribute.TypeName
                : completionContext.Type.Name;

            return(nodeTypeName, idRuntimeType);
        }
        /// <inheritdoc />
        public virtual ExtendedTypeReference GetFieldType(MemberInfo member)
        {
            if (member is null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            if (TryCreateFilterType(_typeInspector.GetReturnType(member, true), out Type? rt))
            {
                return(_typeInspector.GetTypeRef(rt, TypeContext.Input, Scope));
            }

            throw FilterConvention_TypeOfMemberIsUnknown(member);
        }
示例#5
0
        private static IExtendedType GetSourceType(
            ITypeInspector typeInspector,
            ObjectFieldDefinition definition,
            Type entityType)
        {
            // if an explicit result type is defined we will type it since it expresses the
            // intend.
            if (definition.ResultType is not null)
            {
                return(typeInspector.GetType(definition.ResultType));
            }

            // Otherwise we will look at specified members and extract the return type.
            MemberInfo?member = definition.ResolverMember ?? definition.Member;

            if (member is not null)
            {
                return(typeInspector.GetReturnType(member, true));
            }

            // if we were not able to resolve the source type we will assume that it is
            // an enumerable of the entity type.
            return(typeInspector.GetType(typeof(IEnumerable <>).MakeGenericType(entityType)));
        }
 public QueryableSimpleMethodTest(ITypeInspector typeInspector)
 {
     _extendedType = typeInspector.GetReturnType(Method);
 }
 public static ITypeReference GetInputReturnType(
     this ITypeInspector typeInspector,
     MemberInfo member)
 {
     return(typeInspector.GetReturnType(member, TypeContext.Input));
 }