コード例 #1
0
        } //method

        private void RegisterSpecialObjectTypeIfProvided(Type type, TypeRole typeRole, GraphQLModule module)
        {
            if (type == null)
            {
                return;
            }
            var typeName = $"{module.Name}_{type.Name}";
            var typeDef  = new ObjectTypeDef(typeName, type, GraphQLModelObject.EmptyAttributeList, module, typeRole);

            _model.Types.Add(typeDef);
            _model.TypesByClrType.Add(type, typeDef);
        }
コード例 #2
0
ファイル: ModelExtensions.cs プロジェクト: rivantsov/ngraphql
        public static bool TypeIsTransient(this TypeRole typeRole)
        {
            switch (typeRole)
            {
            case TypeRole.ModuleQuery:
            case TypeRole.ModuleMutation:
            case TypeRole.ModuleSubscription:
                return(true);

            default:
                return(false);
            }
        }
コード例 #3
0
ファイル: ModelBuilder.cs プロジェクト: rivantsov/ngraphql
        private ObjectTypeDef BuildRootSchemaObject(string name, TypeRole typeRole, TypeRole moduleTypeRole)
        {
            var allModuleAggrTypes = _model.Types.OfType <ObjectTypeDef>()
                                     .Where(t => t.TypeRole == moduleTypeRole)
                                     .ToList();

            if (allModuleAggrTypes.Count == 0)
            {
                return(null);
            }
            // create root object (ex: Query type)
            var rootObjTypeDef = new ObjectTypeDef(name, null, GraphQLModelObject.EmptyAttributeList, null, typeRole);

            RegisterTypeDef(rootObjTypeDef);
            var mapping = new ObjectTypeMapping(rootObjTypeDef, null);

            rootObjTypeDef.Mappings.Add(mapping);
            // copy resolvers
            foreach (var aggrType in allModuleAggrTypes)
            {
                mapping.FieldResolvers.AddRange(aggrType.Mappings[0].FieldResolvers);
            }
            // collect all fields from collected resolvers
            var allFields = mapping.FieldResolvers.Select(fr => fr.Field).ToList();

            rootObjTypeDef.Fields.AddRange(allFields);
            // check for name duplicates
            var fieldNameDupes = rootObjTypeDef.Fields.Select(f => f.Name).GroupBy(fn => fn).Where(g => g.Count() > 1).ToList();

            if (fieldNameDupes.Count > 0)
            {
                string dupesAll = string.Join(",", fieldNameDupes.Select(g => g.Key));
                AddError($"Duplicate fields defined at top-level type {typeRole}, field names: {dupesAll}");
            }
            // important: re-assign Index value for all fields; we moved fields to aggregate Query, Mutation
            //  objects, so their indexes changed
            ReassignFieldIndexes(rootObjTypeDef);
            return(rootObjTypeDef);
        }
コード例 #4
0
ファイル: ModelClasses.cs プロジェクト: rivantsov/ngraphql
 public ComplexTypeDef(string name, TypeKind kind, Type clrType, IList <Attribute> attrs, GraphQLModule module,
                       TypeRole typeRole = TypeRole.Data)
     : base(name, kind, clrType, attrs, module)
 {
     this.TypeRole = typeRole;
 }
コード例 #5
0
ファイル: ModelClasses.cs プロジェクト: rivantsov/ngraphql
 public ObjectTypeDef(string name, Type clrType, IList <Attribute> attrs, GraphQLModule module,
                      TypeRole typeRole = TypeRole.Data)
     : base(name, TypeKind.Object, clrType, attrs, module, typeRole)
 {
     _possibleOutTypes = new ObjectTypeDef[] { this };
 }