public void builds_directives() { var definitions = @" directive @myDirective( if: Boolean! ) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT "; var schema = Schema.For(definitions); schema.Initialize(); var directive = schema.FindDirective("myDirective"); directive.ShouldNotBeNull(); directive.Arguments.Count().ShouldBe(1); var argument = directive.Arguments.Find("if"); SchemaPrinter.ResolveName(argument.ResolvedType).ShouldBe("Boolean!"); directive.Locations.ShouldBe(new[] { DirectiveLocation.Field, DirectiveLocation.FragmentSpread, DirectiveLocation.InlineFragment }); }
public string Print(GraphType type) { if (_schemaPrinter == null) { _schemaPrinter = new SchemaPrinter(Schema); } return(_schemaPrinter.ResolveName(type)); }
/// <inheritdoc/> public async Task <object> Resolve(IResolveFieldContext context, FieldMiddlewareDelegate next) { var metadata = new Dictionary <string, object> { { "typeName", context.ParentType.Name }, { "fieldName", context.FieldName }, { "returnTypeName", SchemaPrinter.ResolveName(context.ReturnType) }, { "path", context.Path }, }; using (context.Metrics.Subject("field", context.FieldName, metadata)) return(await next(context).ConfigureAwait(false)); }
public static StatsReport From(ISchema schema, Operation operation, PerfRecord[] records, DateTime start) { var operationStat = records.Single(x => string.Equals(x.Category, "operation")); var report = new StatsReport { Start = start, End = start.AddMilliseconds(operationStat.Duration), Duration = operationStat.Duration, Types = TypesFromSchema(schema) }; var perField = new LightweightCache <string, TypeStat>(type => new TypeStat { Name = type }); var typeInfo = new TypeInfo(schema); var fieldVisitor = new EnterLeaveListener(_ => { _.Match <AstField>(f => { var parent = typeInfo.GetParentType().GetNamedType(); var parentType = parent.Name; var fieldName = f.Name; perField[parentType][fieldName].ReturnType = SchemaPrinter.ResolveName(typeInfo.GetLastType()); }); }); new BasicVisitor(typeInfo, fieldVisitor).Visit(operation); var queryResolvers = records.Where(x => string.Equals(x.Category, "field")).ToList(); queryResolvers.Apply(resolver => { var typeName = resolver.MetaField <string>("typeName"); var fieldName = resolver.MetaField <string>("fieldName"); perField[typeName][fieldName].AddLatency(resolver.Duration); }); var operationName = operation.Name ?? "Anonymous"; report.PerSignature[operationName] = new StatsPerSignature { PerType = perField.GetAll() }; return(report); }
public void references_other_types() { var definitions = @" type Post { id: ID! title: String votes: Int } type Query { posts: [Post] post(id: ID = 1): Post } "; var schema = Schema.For(definitions); schema.Initialize(); var query = schema.Query; query.ShouldNotBeNull(); query.Name.ShouldBe("Query"); query.Fields.Count().ShouldBe(2); var posts = query.Fields.First(); posts.Name.ShouldBe("posts"); SchemaPrinter.ResolveName(posts.ResolvedType).ShouldBe("[Post]"); query.Fields.Last().ResolvedType.Name.ShouldBe("Post"); var post = schema.FindType("Post") as IObjectGraphType; post.ShouldNotBeNull(); post.Fields.Count().ShouldBe(3); }
public string Print(IGraphType type) { return(SchemaPrinter.ResolveName(type)); }
/// <summary> /// Returns the name of the specified graph type. /// </summary> public string Print(IGraphType type) => SchemaPrinter.ResolveName(type);