Пример #1
0
        private static void RenameObjectField(
            ObjectTypeDefinitionNode objectType,
            RenameFieldsContext renameContext)
        {
            IReadOnlyCollection <InterfaceTypeDefinitionNode> interfaceTypes =
                GetInterfaceTypes(objectType, renameContext.Types);

            foreach (FieldDefinitionNode fieldDefinition in
                     objectType.Fields)
            {
                NameString originalName =
                    fieldDefinition.GetOriginalName(renameContext.SchemaName);
                if (!originalName.Equals(fieldDefinition.Name.Value))
                {
                    foreach (InterfaceTypeDefinitionNode interfaceType in
                             GetInterfacesThatProvideFieldDefinition(
                                 originalName, interfaceTypes))
                    {
                        RenameInterfaceField(interfaceType,
                                             renameContext, originalName,
                                             fieldDefinition.Name.Value);
                    }
                }
            }
        }
Пример #2
0
        private static void AddNewFieldName(
            ComplexTypeDefinitionNodeBase type,
            RenameFieldsContext renameContext,
            NameString originalFieldName,
            NameString newFieldName)
        {
            FieldDefinitionNode fieldDefinition = type.Fields.FirstOrDefault(
                t => originalFieldName.Equals(t.GetOriginalName(
                                                  renameContext.SchemaName)));

            if (fieldDefinition != null)
            {
                renameContext.RenamedFields[fieldDefinition] = newFieldName;
            }
        }
Пример #3
0
 private static void RenameInterfaceField(
     InterfaceTypeDefinitionNode interfaceType,
     RenameFieldsContext renameContext)
 {
     foreach (FieldDefinitionNode fieldDefinition in
              interfaceType.Fields)
     {
         NameString originalName =
             fieldDefinition.GetOriginalName(renameContext.SchemaName);
         if (!originalName.Equals(fieldDefinition.Name.Value))
         {
             RenameInterfaceField(
                 interfaceType, renameContext,
                 originalName, fieldDefinition.Name.Value);
         }
     }
 }
Пример #4
0
        GetFieldsToRename(
            DocumentNode document,
            NameString schemaName)
        {
            var fieldsToRename =
                new Dictionary <FieldDefinitionNode, NameString>();

            var types = document.Definitions
                        .OfType <ComplexTypeDefinitionNodeBase>()
                        .Where(t => t.IsFromSchema(schemaName))
                        .ToDictionary(t => t.GetOriginalName(schemaName));

            var queue = new Queue <NameString>(types.Keys);

            var context = new RenameFieldsContext(
                types, fieldsToRename, schemaName);

            while (queue.Count > 0)
            {
                string name = queue.Dequeue();

                switch (types[name])
                {
                case ObjectTypeDefinitionNode objectType:
                    RenameObjectField(objectType, context);
                    break;

                case InterfaceTypeDefinitionNode interfaceType:
                    RenameInterfaceField(interfaceType, context);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            return(fieldsToRename);
        }
Пример #5
0
        private static void RenameInterfaceField(
            InterfaceTypeDefinitionNode interfaceType,
            RenameFieldsContext renameContext,
            NameString originalFieldName,
            NameString newFieldName)
        {
            List <ObjectTypeDefinitionNode> objectTypes =
                renameContext.Types.Values
                .OfType <ObjectTypeDefinitionNode>()
                .Where(t => t.Interfaces.Select(i => i.Name.Value)
                       .Any(n => string.Equals(n,
                                               interfaceType.Name.Value,
                                               StringComparison.Ordinal)))
                .ToList();

            AddNewFieldName(interfaceType, renameContext,
                            originalFieldName, newFieldName);

            foreach (ObjectTypeDefinitionNode objectType in objectTypes)
            {
                AddNewFieldName(objectType, renameContext,
                                originalFieldName, newFieldName);
            }
        }