Пример #1
0
        /// <summary>
        /// Register the mutation
        /// </summary>
        /// <param name="provider">The mutation api provider</param>
        /// <param name="apiMutation">The mutation description</param>
        /// <param name="apiRoot">The api root</param>
        /// <param name="typesCreated">The list of created types</param>
        /// <returns>The mutation as merged field </returns>
        private static MergedField RegisterConnectionMutation(
            ApiProvider provider,
            ApiMutation apiMutation,
            MergedApiRoot apiRoot,
            Dictionary <string, MergedType> typesCreated)
        {
            var field          = FindContainer(apiMutation, apiRoot);
            var connectionType = field?.Type as MergedConnectionType;

            if (connectionType == null)
            {
                return(null);
            }

            var errorDescriptionApiType =
                provider.Description.Types.FirstOrDefault(t => t.TypeName == "ErrorDescription") as ApiObjectType;
            MergedType errorDescriptionType = null;

            if (errorDescriptionApiType != null)
            {
                errorDescriptionType = CreateConnectionType(errorDescriptionApiType, provider, typesCreated);
            }

            var returnType = new MergedConnectionMutationResultType(
                connectionType.ElementType,
                apiRoot,
                errorDescriptionType,
                provider);

            typesCreated[returnType.ComplexTypeName] = returnType;

            var inputType = new MergedInputType(apiMutation.Name);

            inputType.AddProvider(
                new FieldProvider {
                Provider = provider, FieldType = new ApiObjectType(apiMutation.Name)
            });
            typesCreated[inputType.ComplexTypeName] = inputType;

            foreach (var apiField in apiMutation.Arguments)
            {
                inputType.Fields.Add(
                    apiField.Name,
                    new MergedField(
                        apiField.Name,
                        CreateMergedType(provider, apiField, null, new List <string>(), true, typesCreated),
                        provider,
                        apiMutation,
                        apiMutation.Flags,
                        description: apiField.Description));
            }

            inputType.Fields["clientMutationId"] = new MergedField(
                "clientMutationId",
                CreateScalarType(EnScalarType.String, typesCreated),
                provider,
                apiMutation);

            var arguments = new Dictionary <string, MergedField>
            {
                {
                    "input",
                    new MergedField(
                        "input",
                        inputType,
                        provider,
                        apiMutation)
                }
            };

            return(new MergedField(
                       apiMutation.Name,
                       returnType,
                       provider,
                       apiMutation,
                       apiMutation.Flags,
                       arguments,
                       apiMutation.Description));
        }
Пример #2
0
        /// <summary>
        /// Register the mutation
        /// </summary>
        /// <param name="provider">The mutation api provider</param>
        /// <param name="apiMutation">The mutation description</param>
        /// <param name="apiRoot">The api root</param>
        /// <param name="typesCreated">The list of created types</param>
        /// <returns>The mutation as merged field </returns>
        private static MergedField RegisterUntypedMutation(
            ApiProvider provider,
            ApiMutation apiMutation,
            MergedApiRoot apiRoot,
            Dictionary <string, MergedType> typesCreated)
        {
            var returnType = CreateMergedType(provider, apiMutation, null, new List <string>(), false, typesCreated);

            var inputType = new MergedInputType(apiMutation.Name);

            inputType.AddProvider(
                new FieldProvider {
                Provider = provider, FieldType = new ApiObjectType(apiMutation.Name)
            });
            typesCreated[inputType.ComplexTypeName] = inputType;

            foreach (var apiField in apiMutation.Arguments)
            {
                inputType.Fields.Add(
                    apiField.Name,
                    new MergedField(
                        apiField.Name,
                        CreateMergedType(provider, apiField, null, new List <string>(), true, typesCreated),
                        provider,
                        apiMutation.Clone(),
                        apiMutation.Flags,
                        description: apiField.Description));
            }

            inputType.Fields["clientMutationId"] = new MergedField(
                "clientMutationId",
                CreateScalarType(EnScalarType.String, typesCreated),
                provider,
                apiMutation);

            var arguments = new Dictionary <string, MergedField>
            {
                {
                    "input",
                    new MergedField(
                        "input",
                        inputType,
                        provider,
                        apiMutation)
                }
            };

            var payload = new MergedUntypedMutationResult(returnType, apiRoot, provider, apiMutation);

            typesCreated[payload.ComplexTypeName] = payload;

            var untypedMutation = new MergedField(
                apiMutation.Name,
                payload,
                provider,
                apiMutation,
                apiMutation.Flags,
                arguments,
                apiMutation.Description);

            return(untypedMutation);
        }