public RenameFieldRewriter(
     FieldReference field,
     NameString newFieldName,
     NameString?schemaName = null)
 {
     Field        = field ?? throw new ArgumentNullException(nameof(field));
     NewFieldName = newFieldName.EnsureNotEmpty(nameof(newFieldName));
     SchemaName   = schemaName?.EnsureNotEmpty(nameof(schemaName));
 }
示例#2
0
 public RenameTypeRewriter(
     NameString originalTypeName,
     NameString newTypeName,
     NameString?schemaName = null)
 {
     OriginalTypeName = originalTypeName.EnsureNotEmpty(nameof(originalTypeName));
     NewTypeName      = newTypeName.EnsureNotEmpty(nameof(newTypeName));
     SchemaName       = schemaName?.EnsureNotEmpty(nameof(schemaName));
 }
示例#3
0
 public FieldCoordinate(
     NameString typeName,
     NameString fieldName,
     NameString?argumentName = null)
 {
     TypeName     = typeName.EnsureNotEmpty(nameof(typeName));
     FieldName    = fieldName.EnsureNotEmpty(nameof(fieldName));
     ArgumentName = argumentName?.EnsureNotEmpty(nameof(argumentName));
     HasValue     = true;
 }
        public IValueNode RewriteValueNode(
            NameString sourceSchema,
            IInputType inputType,
            IValueNode value)
        {
            sourceSchema.EnsureNotEmpty(nameof(sourceSchema));

            var context = new Context(sourceSchema, null, null, null);

            context.InputType = inputType;
            return(RewriteValue(value, context));
        }
示例#5
0
        public ExtractedField ExtractField(
            NameString sourceSchema,
            DocumentNode document,
            OperationDefinitionNode operation,
            IFieldSelection selection,
            INamedOutputType declaringType)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            if (selection == null)
            {
                throw new ArgumentNullException(nameof(selection));
            }

            if (declaringType == null)
            {
                throw new ArgumentNullException(nameof(declaringType));
            }

            sourceSchema.EnsureNotEmpty(nameof(sourceSchema));

            var context = new Context(
                sourceSchema, declaringType,
                document, operation);

            var syntaxNodes = new List <FieldNode>();

            foreach (FieldNode syntaxNode in selection.SyntaxNodes)
            {
                FieldNode field = RewriteField(syntaxNode, context);

                if (selection.Field.Type.NamedType().IsLeafType() ||
                    (field.SelectionSet is not null &&
                     field.SelectionSet.Selections.Count > 0))
                {
                    syntaxNodes.Add(field);
                }
            }

            return(new ExtractedField(
                       syntaxNodes,
                       context.Variables.Values.ToList(),
                       context.Fragments.Values.ToList()));
        }
示例#6
0
        public string Serialize(NameString typeName, object id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            typeName.EnsureNotEmpty("typeName");

            return(ToBase64String(
                       SerializeTypeName(typeName),
                       SerializeId(id)));
        }
示例#7
0
        public static IEnumerable <FieldMember> DiscoverResolvableMembers(
            Type resolverType, NameString typeName)
        {
            if (resolverType == null)
            {
                throw new ArgumentNullException(nameof(resolverType));
            }

            typeName.EnsureNotEmpty(nameof(typeName));

            return(GetProperties(resolverType, typeName)
                   .Concat(GetMethods(resolverType, typeName)));
        }
示例#8
0
        public ISchemaMerger AddSchema(NameString name, DocumentNode schema)
        {
            if (schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }

            name.EnsureNotEmpty(nameof(name));

            _schemas.Add(name, schema);

            return(this);
        }
示例#9
0
        public bool TryGetField(NameString fieldName, [NotNullWhen(true)] out T?field)
        {
            if (_fieldsLookup.TryGetValue(
                    fieldName.EnsureNotEmpty(nameof(fieldName)),
                    out var item))
            {
                field = item;
                return(true);
            }

            field = default;
            return(false);
        }
示例#10
0
    public DirectiveType GetDirectiveType(NameString directiveName)
    {
        if (_directiveTypes.TryGetValue(
                directiveName.EnsureNotEmpty(nameof(directiveName)),
                out DirectiveType? type))
        {
            return(type);
        }

        throw new ArgumentException(
                  string.Format(TypeResources.Schema_GetDirectiveType_DoesNotExist, directiveName),
                  nameof(directiveName));
    }
 public RenameFieldArgumentRewriter(
     NameString schemaName,
     FieldReference field,
     NameString argumentName,
     NameString newArgumentName)
 {
     SchemaName   = schemaName.EnsureNotEmpty(nameof(schemaName));
     Field        = field ?? throw new ArgumentNullException(nameof(field));
     ArgumentName = argumentName
                    .EnsureNotEmpty(nameof(argumentName));
     NewArgumentName = newArgumentName
                       .EnsureNotEmpty(nameof(newArgumentName));
 }
示例#12
0
 protected BooleanFilterOperationDescriptorBase(
     IDescriptorContext context,
     NameString name,
     ITypeReference type,
     FilterOperation operation)
     : base(context)
 {
     Definition.Name = name.EnsureNotEmpty(nameof(name));
     Definition.Type = type
                       ?? throw new ArgumentNullException(nameof(type));
     Definition.Operation = operation
                            ?? throw new ArgumentNullException(nameof(operation));
 }
示例#13
0
        public bool TryGetVariable <T>(NameString name, out T value)
        {
            name.EnsureNotEmpty("name");

            if (_variables.TryGetValue(name, out VariableValue variableValue))
            {
                object coercedValue = null;

                if (typeof(T) == typeof(object))
                {
                    coercedValue = variableValue.Literal == null
                        ? variableValue.Value
                        : variableValue.Literal;
                }
                else if (typeof(IValueNode).IsAssignableFrom(typeof(T)))
                {
                    if (variableValue.Literal == null)
                    {
                        coercedValue = variableValue.Type.ParseValue(variableValue.Value);
                    }
                    else
                    {
                        coercedValue = variableValue.Literal;
                    }
                }
                else
                {
                    if (variableValue.Literal == null)
                    {
                        coercedValue = variableValue.Value;
                    }
                    else
                    {
                        coercedValue = variableValue.Type.ParseLiteral(variableValue.Literal);
                    }
                }

                if (coercedValue is T castedValue)
                {
                    value = castedValue;
                }
                else
                {
                    value = (T)_converter.Convert(typeof(object), typeof(T), coercedValue);
                }
                return(true);
            }

            value = default;
            return(false);
        }
示例#14
0
        public static IStitchingBuilder IgnoreRootTypes(
            this IStitchingBuilder builder,
            NameString schemaName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            schemaName.EnsureNotEmpty(nameof(schemaName));

            return(builder.AddDocumentRewriter(
                       new RemoveRootTypeRewriter(schemaName)));
        }
        public static IRequestExecutorBuilder IgnoreType(
            this IRequestExecutorBuilder builder,
            NameString typeName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            typeName.EnsureNotEmpty(nameof(typeName));

            return(builder.AddDocumentRewriter(
                       new RemoveTypeRewriter(typeName)));
        }
示例#16
0
        public static ISchemaMerger IgnoreType(
            this ISchemaMerger schemaMerger,
            NameString typeName)
        {
            if (schemaMerger == null)
            {
                throw new ArgumentNullException(nameof(schemaMerger));
            }

            typeName.EnsureNotEmpty(nameof(typeName));

            return(schemaMerger.AddDocumentRewriter(
                       new RemoveTypeRewriter(typeName)));
        }
示例#17
0
        public ISchema GetRemoteSchema(NameString schemaName)
        {
            schemaName.EnsureNotEmpty(nameof(schemaName));

            if (_clients.TryGetValue(schemaName, out RemoteQueryClient client))
            {
                return client.Executor.Schema;
            }

            throw new ArgumentException(string.Format(
                CultureInfo.InvariantCulture,
                StitchingResources.SchemaName_NotFound,
                schemaName));
        }
示例#18
0
        public IRemoteRequestExecutor GetRemoteRequestExecutor(NameString schemaName)
        {
            schemaName.EnsureNotEmpty(nameof(schemaName));

            if (_executors.TryGetValue(schemaName, out RemoteRequestExecutor? executor))
            {
                return(executor);
            }

            throw new ArgumentException(string.Format(
                                            CultureInfo.InvariantCulture,
                                            StitchingResources.SchemaName_NotFound,
                                            schemaName));
        }
        public static bool IsFromSchema(
            this INamedSyntaxNode typeDefinition,
            NameString schemaName)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException(nameof(typeDefinition));
            }

            schemaName.EnsureNotEmpty(nameof(schemaName));

            return(typeDefinition.Directives.Any(t =>
                                                 HasSourceDirective(t, schemaName)));
        }
示例#20
0
        public bool TryGetTypeRef(
            NameString typeName,
            [NotNullWhen(true)] out ITypeReference?typeRef)
        {
            typeName.EnsureNotEmpty(nameof(typeName));

            if (!_nameRefs.TryGetValue(typeName, out typeRef))
            {
                typeRef = Types
                          .FirstOrDefault(t => !t.IsExtension && t.Type.Name.Equals(typeName))
                          ?.References[0];
            }
            return(typeRef is not null);
        }
        public static ISchemaMerger IgnoreRootTypes(
            this ISchemaMerger schemaMerger,
            NameString?schemaName = null)
        {
            if (schemaMerger == null)
            {
                throw new ArgumentNullException(nameof(schemaMerger));
            }

            schemaName?.EnsureNotEmpty(nameof(schemaName));

            return(schemaMerger.AddDocumentRewriter(
                       new RemoveRootTypeRewriter(schemaName)));
        }
示例#22
0
        public string Serialize(NameString typeName, object id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            typeName.EnsureNotEmpty("typeName");

            byte[] serializedIdArray = null;
            (byte type, byte[] value)serializedId = SerializeId(id);
            int  length        = typeName.Value.Length + serializedId.value.Length + 2;
            bool useStackalloc = length <= _stackallocThreshold;

            // TODO : we have to first reimplemet the base 64 algorithm in order
            // to take advantage of span.
            // Span<byte> serializedIdSpan = useStackalloc
            //     ? stackalloc byte[length]
            //     : (serializedIdArray = ArrayPool<byte>.Shared.Rent(length));
            serializedIdArray = ArrayPool <byte> .Shared.Rent(length);

            //serializedIdSpan = serializedIdSpan.Slice(0, length);
            Span <byte> serializedIdSpan = serializedIdArray.AsSpan();

            int index = 0;

            for (int i = 0; i < typeName.Value.Length; i++)
            {
                serializedIdSpan[index++] = (byte)typeName.Value[i];
            }

            serializedIdSpan[index++] = _separator;
            serializedIdSpan[index++] = serializedId.type;

            for (int i = 0; i < serializedId.value.Length; i++)
            {
                serializedIdSpan[index++] = (byte)serializedId.value[i];
            }

            string value = Convert.ToBase64String(serializedIdArray, 0, length);

            if (serializedIdArray != null)
            {
                serializedIdSpan.Clear();
                ArrayPool <byte> .Shared.Return(serializedIdArray);
            }

            return(value);
        }
示例#23
0
        public T GetVariable <T>(NameString name)
        {
            name.EnsureNotEmpty("name");

            if (!TryGetVariable(name, out T variableValue))
            {
                throw new QueryException(ErrorBuilder.New()
                                         .SetMessage(CoreResources
                                                     .VariableCollection_VariableNotDeclared)
                                         .SetExtension(nameof(name), name)
                                         .Build());
            }

            return(variableValue);
        }
        protected void DependsOn(
            NameString typeName,
            bool mustBeNamedOrCompleted)
        {
            typeName.EnsureNotEmpty(nameof(typeName));

            TypeDependencyKind kind = mustBeNamedOrCompleted
                ? DependencyKind
                : TypeDependencyKind.Default;

            _configuration.AddDependency(
                new TypeDependency(
                    TypeReference.Create(new NamedTypeNode(typeName), TypeContext.None),
                    kind));
        }
        protected void Argument(
            NameString name,
            Action <IArgumentDescriptor> argument)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(nameof(argument));
            }

            var descriptor = new ArgumentDescriptor(
                name.EnsureNotEmpty(nameof(name)));

            argument(descriptor);
            FieldDescription.Arguments.Add(descriptor.CreateDescription());
        }
 public DependantFactoryTypeReference(
     NameString name,
     ITypeReference dependency,
     Func <IDescriptorContext, TypeSystemObjectBase> factory,
     TypeContext context,
     string?scope = null)
     : base(
         TypeReferenceKind.DependantFactory,
         context,
         scope)
 {
     Name       = name.EnsureNotEmpty(nameof(name));
     Dependency = dependency ?? throw new ArgumentNullException(nameof(dependency));
     Factory    = factory ?? throw new ArgumentNullException(nameof(factory));
 }
示例#27
0
 public OutputFieldModel(
     NameString name,
     string?description,
     IOutputField field,
     IOutputType type,
     FieldNode syntaxNode,
     Path path)
 {
     Name        = name.EnsureNotEmpty(nameof(name));
     Description = description;
     Field       = field ?? throw new ArgumentNullException(nameof(field));
     SyntaxNode  = syntaxNode ?? throw new ArgumentNullException(nameof(syntaxNode));
     Path        = path ?? throw new ArgumentNullException(nameof(path));
     Type        = type ?? throw new ArgumentNullException(nameof(type));
 }
 protected StringFilterOperationDescriptor(
     IDescriptorContext context,
     StringFilterFieldDescriptor descriptor,
     NameString name,
     ITypeReference type,
     FilterOperation operation)
     : base(context)
 {
     Definition.Name = name.EnsureNotEmpty(nameof(name));
     Definition.Type = type
                       ?? throw new ArgumentNullException(nameof(type));
     Definition.Operation = operation
                            ?? throw new ArgumentNullException(nameof(operation));
     _descriptor = descriptor
                   ?? throw new ArgumentNullException(nameof(descriptor));
 }
示例#29
0
 public LeafTypeModel(
     NameString name,
     string?description,
     ILeafType type,
     string serializationType,
     string runtimeType)
 {
     Name        = name.EnsureNotEmpty(nameof(name));
     Description = description;
     Type        = type ??
                   throw new ArgumentNullException(nameof(type));
     SerializationType = serializationType ??
                         throw new ArgumentNullException(nameof(serializationType));
     RuntimeType = runtimeType ??
                   throw new ArgumentNullException(nameof(runtimeType));
 }
        public static IRequestExecutorBuilder RenameType(
            this IRequestExecutorBuilder builder,
            NameString originalTypeName,
            NameString newTypeName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            originalTypeName.EnsureNotEmpty(nameof(originalTypeName));
            newTypeName.EnsureNotEmpty(nameof(newTypeName));

            return(builder.AddTypeRewriter(
                       new RenameTypeRewriter(originalTypeName, newTypeName)));
        }