Exemplo n.º 1
0
        private void FillArgs(string name, Type graphType)
        {
            if (TableArgs == null)
            {
                TableArgs = new QueryArguments(
                    new QueryArgument(graphType)
                {
                    Name = name
                }
                    );
            }
            else
            {
                TableArgs.Add(new QueryArgument(graphType)
                {
                    Name = name
                });
            }

            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "pageNumber"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "pageSize"
            });
            TableArgs.Add(new QueryArgument <StringGraphType> {
                Name = "rawQuery"
            });
        }
Exemplo n.º 2
0
        private void InitGraphField(Field field, Dictionary <string, CollectionSchema> collections = null, GraphQLService graphQLService = null)
        {
            Type graphQLType;

            if (field.BaseType == FieldBaseType.Object)
            {
                var relatedObject     = collections[field.Type];
                var relatedCollection = new CollectionType(relatedObject, collections);
                var listType          = new ListGraphType(relatedCollection);
                graphQLType = relatedCollection.GetType();
                FieldType columnField = Field(
                    graphQLType,
                    relatedObject.CollectionName);

                columnField.Resolver  = new NameFieldResolver();
                columnField.Arguments = new QueryArguments(relatedCollection.TableArgs);
                foreach (var arg in columnField.Arguments.Where(x => !(new string[] { "pageNumber", "pageSize", "rawQuery", "_id" }.Contains(x.Name))).ToList())
                {
                    arg.Name = $"{relatedObject.CollectionName}_{arg.Name}";
                    TableArgs.Add(arg);
                }
            }
            else
            {
                //graphQLType = (ResolveFieldMetaType(field.BaseType)).GetGraphTypeFromType(!field.Required);
                graphQLType = (ResolveFieldMetaType(field.BaseType)).GetGraphTypeFromType(true);
                FieldType columnField = Field(
                    graphQLType,
                    field.Name);

                columnField.Resolver = new NameFieldResolver();
                FillArgs(field.Name, graphQLType);
            }
        }
Exemplo n.º 3
0
        public EntityType(EntityType entityType, IEnumerable <FieldType> fields)
        {
            Name = entityType.Name;
            this.SqlTable(Name, "id");
            _dialect = new SQLiteDialect();

            fields.ToList().ForEach(f =>
            {
                FillArgs(f.Name);
                this.AddField(f);
            });

            TableArgs.Add(new QueryArgument <IdGraphType> {
                Name = "number"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "first"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "offset"
            });
            TableArgs.Add(new QueryArgument <StringGraphType> {
                Name = "includes"
            });
        }
Exemplo n.º 4
0
        private void FillArgs(string columnName)
        {
            if (TableArgs == null)
            {
                TableArgs = new QueryArguments(
                    new QueryArgument <StringGraphType>()
                {
                    Name = columnName
                }
                    );
            }
            else
            {
                TableArgs.Add(new QueryArgument <StringGraphType> {
                    Name = columnName
                });
            }

            TableArgs.Add(new QueryArgument <IdGraphType> {
                Name = "id"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "first"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "offset"
            });
        }
Exemplo n.º 5
0
        public JObjectRawType(GraphQLQuery query, GraphQLService graphQLService, CollectionSchema collectionSchema, EntityService entityService)
        {
            _query            = query;
            _graphQLService   = graphQLService;
            _collectionSchema = collectionSchema;
            _entityService    = entityService;

            Name = collectionSchema.CollectionName;
            var fields = entityService.GetTypes();

            foreach (Field field in collectionSchema.FieldSettings)
            {
                BuildGraphField(field);
            }

            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "pageNumber"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "pageSize"
            });
            TableArgs.Add(new QueryArgument <StringGraphType> {
                Name = "rawQuery"
            });
        }
Exemplo n.º 6
0
        private void FillArgs(string columnName)
        {
            var dataType = ReflectionHelper.GetPropertyType(_type, columnName);

            if (TableArgs == null)
            {
                TableArgs = new QueryArguments();
                TableArgs.Add(new QueryArgument <IntGraphType> {
                    Name = "first"
                });
                TableArgs.Add(new QueryArgument <IntGraphType> {
                    Name = "offset"
                });
            }
            if (dataType != null)
            {
                switch (dataType.Name)
                {
                case "Int32":
                    TableArgs.Add(new QueryArgument <IntGraphType> {
                        Name = columnName
                    });
                    break;

                case "DateTime":
                    TableArgs.Add(new QueryArgument <DateGraphType> {
                        Name = columnName
                    });
                    break;

                case "Boolean":
                    TableArgs.Add(new QueryArgument <BooleanGraphType> {
                        Name = columnName
                    });
                    break;

                default:
                    TableArgs.Add(new QueryArgument <StringGraphType> {
                        Name = columnName
                    });
                    break;
                }
            }
            //TableArgs.Add(new QueryArgument<IntGraphType> { Name = "id" });
            //TableArgs.Add(new QueryArgument<IntGraphType> { Name = "first" });
            //TableArgs.Add(new QueryArgument<IntGraphType> { Name = "offset" });
        }
Exemplo n.º 7
0
 private void FillArgs(string columnName)
 {
     if (TableArgs == null)
     {
         TableArgs = new QueryArguments(
             new QueryArgument <StringGraphType>()
         {
             Name = columnName
         }
             );
     }
     else
     {
         TableArgs.Add(new QueryArgument <StringGraphType> {
             Name = columnName
         });
     }
 }
Exemplo n.º 8
0
        public EntityType(EntityMetadata tableMetadata)
        {
            Name = tableMetadata.TableName;
            this.SqlTable(tableMetadata.TableName, "id");
            foreach (var tableColumn in tableMetadata.Columns)
            {
                InitGraphTableColumn(tableColumn, Name);
            }
            _dialect = new SQLiteDialect();


            TableArgs.Add(new QueryArgument <IdGraphType> {
                Name = "number"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "first"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "offset"
            });
            TableArgs.Add(new QueryArgument <StringGraphType> {
                Name = "includes"
            });
            if (EntitiesAlreadyCreated.ContainsKey(tableMetadata.TableName))
            {
                EntitiesAlreadyCreated.Remove(tableMetadata.TableName);
            }

            EntityType x = this;
            var        y = (EntityType)this.Fields.FirstOrDefault(f => !string.IsNullOrEmpty(f.Description))?.ResolvedType;

            if (y != null)
            {
                var yy = (EntityType)y.Fields.FirstOrDefault(f => !string.IsNullOrEmpty(f.Description))?.ResolvedType;
                var zz = yy?.Fields.FirstOrDefault(f => f.Name == tableMetadata.EntityName);
                if (zz != null)
                {
                    var list = yy.Fields.Where(f => f.Name != tableMetadata.EntityName);
                    x = new EntityType(this, list);
                }
            }

            EntitiesAlreadyCreated.Add(tableMetadata.TableName, x);
        }
Exemplo n.º 9
0
 private void FillArgs(string name, Type graphType)
 {
     if (TableArgs == null)
     {
         TableArgs = new QueryArguments(
             new QueryArgument(graphType)
         {
             Name = name
         }
             );
     }
     else
     {
         TableArgs.Add(new QueryArgument(graphType)
         {
             Name = name
         });
     }
 }
Exemplo n.º 10
0
        public TableType(TableMetadata tableMetadata)
        {
            Name = tableMetadata.TableName;
            foreach (var tableColumn in tableMetadata.Columns)
            {
                InitGraphTableColumn(tableColumn);
            }

            TableArgs.Add(new QueryArgument <IdGraphType> {
                Name = "id"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "first"
            });
            TableArgs.Add(new QueryArgument <IntGraphType> {
                Name = "offset"
            });
            TableArgs.Add(new QueryArgument <StringGraphType> {
                Name = "includes"
            });
        }
Exemplo n.º 11
0
        private void BuildGraphField(Field field)
        {
            Type graphQLType;
            var  f = _entityService.GetTypes().FirstOrDefault(x => x.TypeName == field.Type);

            if (f?.GraphType == FieldGraphType.Relation)
            {
                var collectionName = field.Options["Collection"].Value <string>();
                var fieldType      = _query.Fields.FirstOrDefault(x => x.Name == collectionName);
                if (fieldType == null)
                {
                    //Add related collection not registred on schema
                    var relatedObject = _entityService.GetCollectionSchemas().FirstOrDefault(x => x.CollectionName == collectionName);
                    var type          = new JObjectRawType(_query, _graphQLService, relatedObject, _entityService);
                    var listType      = new ListGraphType(type);

                    fieldType = new FieldType
                    {
                        Name         = collectionName,
                        Type         = listType.GetType(),
                        ResolvedType = listType,
                        Resolver     = new JObjectFieldResolver(_graphQLService, _entityService),
                        Arguments    = new QueryArguments(
                            type.TableArgs
                            )
                    };

                    _query.AddField(fieldType);
                }

                var subType         = fieldType.GetType();
                var subresolvedType = fieldType.ResolvedType;
                //if (!field.Options["Multiple"].Value<bool>())
                //{
                //    var relatedObject = _entityService.GetCollectionSchemas().FirstOrDefault(x => x.CollectionName == collectionName);
                //    subresolvedType = new JObjectRawType(_query, _graphQLService, relatedObject, _entityService);
                //    subType = subresolvedType.GetType();
                //}

                var subField = new FieldType
                {
                    Name         = fieldType.Name,
                    Type         = subType,
                    ResolvedType = subresolvedType,
                    Resolver     = new NameFieldResolver(),
                    Arguments    = fieldType.Arguments
                };

                AddField(subField);

                foreach (var arg in fieldType.Arguments.Where(x => !(new string[] { "pageNumber", "pageSize", "rawQuery", "_id" }.Contains(x.Name))).ToList())
                {
                    arg.Name = $"{collectionName}_{arg.Name}";
                    TableArgs.Add(arg);
                }
            }
            else
            {
                //graphQLType = (ResolveFieldMetaType(field.BaseType)).GetGraphTypeFromType(!field.Required);
                graphQLType = (ResolveFieldMetaType(f?.GraphType ?? FieldGraphType.String)).GetGraphTypeFromType(true);
                FieldType columnField = Field(
                    graphQLType,
                    field.Name);

                columnField.Resolver = new NameFieldResolver();
                FillArgs(field.Name, graphQLType);
            }
        }