public GraphQLQuery(GraphQLService graphQLService, EntityService entityService) { Name = "Query"; var schemas = entityService.GetCollectionSchemas(); foreach (var metaColl in schemas) { if (Fields.Count(x => x.Name == metaColl.CollectionName) == 0) { JObjectRawType type = new JObjectRawType(this, graphQLService, metaColl, entityService); ListGraphType listType = new ListGraphType(type); AddField(new FieldType { Name = metaColl.CollectionName, Type = listType.GetType(), ResolvedType = listType, Resolver = new JObjectFieldResolver(graphQLService, entityService), Arguments = new QueryArguments( type.TableArgs ) }); } } }
public GraphQLQuery(DbDataAdapter data, IDatabaseMetadata dbMetadata) { _dbMetadata = dbMetadata; _dbAdapter = data; Name = "Query"; foreach (var metaTable in _dbMetadata.GetMetadataTables()) { var tableType = new TableType(metaTable); this.AddField(new FieldType() { Name = metaTable.TableName, Type = tableType.GetType(), ResolvedType = tableType, Resolver = new MyFieldResolver(metaTable, _dbAdapter), Arguments = new QueryArguments( tableType.TableArgs ) }); //lets add key to get list of current table var listType = new ListGraphType(tableType); this.AddField(new FieldType { Name = $"{metaTable.TableName}_list", Type = listType.GetType(), ResolvedType = listType, Resolver = new MyFieldResolver(metaTable, _dbAdapter), Arguments = new QueryArguments( tableType.TableArgs ) }); } }
public void test_inputs() { var innerObject = new InputObjectGraphType(); innerObject.AddField(new FieldType { Name = "test", ResolvedType = new StringGraphType(), Type = typeof(StringGraphType) }); var list = new ListGraphType(innerObject); var inputObj = new InputObjectGraphType(); inputObj.AddField(new FieldType { Name = "list", ResolvedType = list, Type = list.GetType() }); var obj = new ObjectGraphType(); var field = new FieldType { Name = "hello", ResolvedType = new StringGraphType(), Type = typeof(StringGraphType), Arguments = new QueryArguments { new QueryArgument(inputObj) { Name = "input" } } }; obj.AddField(field); var schema = new Schema { Query = obj }; schema.Initialize(); }
public void test_outputs() { var innerObject = new ObjectGraphType(); innerObject.AddField(new FieldType { Name = "test", ResolvedType = new StringGraphType(), Type = typeof(StringGraphType) }); var list = new ListGraphType(innerObject); var obj = new ObjectGraphType(); obj.AddField(new FieldType { Name = "list", ResolvedType = list, Type = list.GetType() }); var schema = new Schema { Query = obj }; schema.Initialize(); }
public GraphQLQuery( DbContext dbContext, IDatabaseMetadata dbMetadata, ITableNameLookup tableNameLookup) { _dbMetadata = dbMetadata; _tableNameLookup = tableNameLookup; _dbContext = dbContext; Name = "Query"; foreach (var metaTable in _dbMetadata.GetTableMetadatas()) { var tableType = new TableType(metaTable); var friendlyTableName = _tableNameLookup.GetFriendlyName(metaTable.TableName); AddField(new FieldType { Name = friendlyTableName, Type = tableType.GetType(), ResolvedType = tableType, Resolver = new MyFieldResolver(metaTable, _dbContext), Arguments = new QueryArguments( tableType.TableArgs ) }); // lets add key to get list of current table var listType = new ListGraphType(tableType); AddField(new FieldType { Name = $"{friendlyTableName}_list", Type = listType.GetType(), ResolvedType = listType, Resolver = new MyFieldResolver(metaTable, _dbContext), Arguments = new QueryArguments( tableType.TableArgs ) }); } }
public GraphQLQuery(GraphQLService graphQLService) { Name = "Query"; foreach (var key in graphQLService.Collections.Keys) { Library.Schema.CollectionSchema metaColl = graphQLService.Collections[key]; CollectionType type = new CollectionType(metaColl, graphQLService.Collections, graphQLService); ListGraphType listType = new ListGraphType(type); AddField(new FieldType { Name = metaColl.CollectionName, Type = listType.GetType(), ResolvedType = listType, Resolver = new JObjectFieldResolver(graphQLService), Arguments = new QueryArguments( type.TableArgs ) }); } }
public GraphQLQuery( DbContext dbContext, IDatabaseMetadata dbMetadata, ITableNameLookup tableNameLookup) { _dbMetadata = dbMetadata; _tableNameLookup = tableNameLookup; _dbContext = dbContext; Name = "Query"; var assem = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.ManifestModule.Name == "Mix.Cms.Lib.dll"); foreach (var metaTable in _dbMetadata.GetTableMetadatas()) { var type = assem.GetType(metaTable.AssemblyFullName); var tableType = new TableType(metaTable, type); var friendlyTableName = metaTable.TableName; // _tableNameLookup.GetFriendlyName(metaTable.TableName); AddField(new FieldType { Name = friendlyTableName, Type = tableType.GetType(), ResolvedType = tableType, Resolver = new MyFieldResolver(metaTable, _dbContext), Arguments = new QueryArguments(tableType.TableArgs) }); // lets add key to get list of current table var listType = new ListGraphType(tableType); AddField(new FieldType { Name = $"{friendlyTableName}_list", Type = listType.GetType(), ResolvedType = listType, Resolver = new MyFieldResolver(metaTable, _dbContext), Arguments = new QueryArguments( tableType.TableArgs ) }); } }
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); } }