Esempio n. 1
0
        internal override void Merge(
            ITypeCompletionContext context,
            INamedType type)
        {
            if (type is EnumType enumType)
            {
                TypeExtensionHelper.MergeContextData(
                    Definition,
                    enumType.Definition);

                TypeExtensionHelper.MergeDirectives(
                    context,
                    Definition.Directives,
                    enumType.Definition.Directives);

                TypeExtensionHelper.MergeConfigurations(
                    Definition.Configurations,
                    enumType.Definition.Configurations);

                MergeValues(context, Definition, enumType.Definition);
            }
            else
            {
                throw new ArgumentException(
                          TypeResources.EnumTypeExtension_CannotMerge,
                          nameof(type));
            }
        }
Esempio n. 2
0
        internal override void Merge(
            ITypeCompletionContext context,
            INamedType type)
        {
            if (type is ObjectType objectType)
            {
                TypeExtensionHelper.MergeContextData(
                    Definition,
                    objectType.Definition);

                TypeExtensionHelper.MergeDirectives(
                    context,
                    Definition.Directives,
                    objectType.Definition.Directives);

                TypeExtensionHelper.MergeInterfaces(
                    Definition,
                    objectType.Definition);

                TypeExtensionHelper.MergeObjectFields(
                    context,
                    objectType.Definition.RuntimeType,
                    Definition.Fields,
                    objectType.Definition.Fields);

                TypeExtensionHelper.MergeConfigurations(
                    Definition.Configurations,
                    objectType.Definition.Configurations);
            }
            else
            {
                throw new ArgumentException(
                          TypeResources.ObjectTypeExtension_CannotMerge);
            }
        }
        internal override void Merge(
            ICompletionContext context,
            INamedType type)
        {
            if (type is UnionType unionType)
            {
                TypeExtensionHelper.MergeContextData(
                    Definition,
                    unionType.Definition);

                TypeExtensionHelper.MergeDirectives(
                    context,
                    Definition.Directives,
                    unionType.Definition.Directives);

                TypeExtensionHelper.MergeTypes(
                    Definition.Types,
                    unionType.Definition.Types);

                TypeExtensionHelper.MergeConfigurations(
                    Definition.Configurations,
                    unionType.Definition.Configurations);
            }
            else
            {
                throw new ArgumentException(
                          TypeResources.UnionTypeExtension_CannotMerge);
            }
        }
        internal override void Merge(
            ICompletionContext context,
            INamedType type)
        {
            if (type is InputObjectType inputObjectType)
            {
                TypeExtensionHelper.MergeContextData(
                    Definition,
                    inputObjectType.Definition);

                TypeExtensionHelper.MergeDirectives(
                    context,
                    Definition.Directives,
                    inputObjectType.Definition.Directives);

                TypeExtensionHelper.MergeInputObjectFields(
                    context,
                    Definition.Fields,
                    inputObjectType.Definition.Fields);
            }
            else
            {
                throw new ArgumentException(
                          TypeResources.InputObjectTypeExtension_CannotMerge,
                          nameof(type));
            }
        }
        internal override void Merge(
            ICompletionContext context,
            INamedType type)
        {
            if (type is InterfaceType interfaceType)
            {
                TypeExtensionHelper.MergeContextData(
                    Definition,
                    interfaceType.Definition);

                TypeExtensionHelper.MergeDirectives(
                    context,
                    Definition.Directives,
                    interfaceType.Definition.Directives);

                TypeExtensionHelper.MergeInterfaceFields(
                    context,
                    Definition.Fields,
                    interfaceType.Definition.Fields);
            }
            else
            {
                // TODO : resources
                throw new ArgumentException("CANNOT MERGE");
            }
        }
Esempio n. 6
0
        private void MergeValues(
            ITypeCompletionContext context,
            EnumTypeDefinition extension,
            EnumTypeDefinition type)
        {
            foreach (EnumValueDefinition enumValue in
                     extension.Values.Where(t => t.Value != null))
            {
                if (type.RuntimeType.IsInstanceOfType(enumValue.Value))
                {
                    EnumValueDefinition?existingValue =
                        type.Values.FirstOrDefault(t =>
                                                   enumValue.Value.Equals(t.Value));

                    if (existingValue is null)
                    {
                        type.Values.Add(enumValue);
                    }
                    else
                    {
                        TypeExtensionHelper.MergeContextData(enumValue, existingValue);

                        TypeExtensionHelper.MergeDirectives(
                            context,
                            enumValue.Directives,
                            existingValue.Directives);
                    }
                }
                else
                {
                    context.ReportError(
                        SchemaErrorBuilder.New()
                        .SetMessage(string.Format(
                                        CultureInfo.InvariantCulture,
                                        TypeResources.EnumTypeExtension_ValueTypeInvalid,
                                        enumValue.Value))
                        .SetTypeSystemObject(this)
                        .Build());
                }
            }
        }