public void Can_Ignore_Unwanted_Types() { // Ignore specific types from the 'Unwanted' namespace. var schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter()) .IgnoreTypes((Type t, MemberInfo m) => { // Ignore based on the type: if (t == typeof(Unwanted.QueryType3)) { return(true); } // Ignore based on name of the method: if (m != null && m.Name == "UpdateSomethingIgnored") { return(true); } return(false); }) .Build( typeof(SchemaType1), typeof(SchemaType2), typeof(Unwanted.SchemaType3) ); schema.ShouldHaveQueries(3); schema.ShouldHaveMutations(1); schema.Query.ShouldHaveFieldWithName("foo"); schema.Query.ShouldHaveFieldWithName("bar"); schema.Query.ShouldHaveFieldWithName("baz"); schema.Query.ShouldNotHaveFieldWithName("bazIgnored"); schema.Mutation.ShouldHaveFieldWithName("updateSomething"); schema.Mutation.ShouldNotHaveFieldWithName("updateSomethingIgnored"); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var typeAdapter = new GraphTypeAdapter(); var constructor = new SchemaConstructor <ISchema, IGraphType>(typeAdapter); var schema = constructor.Build(typeof(SchemaDefinition <GraphQl.Query, GraphQl.Mutation, GraphQl.Subscription>)); var graphQLEngine = new GraphQLEngine() .WithFieldResolutionStrategy(FieldResolutionStrategy.Normal) .WithQuery <GraphQl.Query>() .WithMutation <GraphQl.Mutation>() .WithSubscription <GraphQl.Subscription>() .BuildSchema(); services.AddSingleton <MessageService>(); services.AddSingleton(schema); services.AddMvc(); services.AddTransient <IDependencyInjector, Injector>(); services.AddSingleton(provider => graphQLEngine); services.AddSingleton <IDocumentExecuter, GraphQL.Conventions.DocumentExecuter>(); services.AddSingleton <IDocumentWriter>(x => { var jsonSerializerSettings = x.GetRequiredService <IOptions <JsonSerializerSettings> >(); return(new DocumentWriter(Formatting.None, jsonSerializerSettings.Value)); }); services.AddTransient(typeof(IGraphQLExecuter <>), typeof(DefaultGraphQLExecuter <>)); services.AddTransient <IWebSocketConnectionFactory <ISchema>, WebSocketConnectionFactory <ISchema> >(); services.AddTransient <IOperationMessageListener, LogMessagesListener>(); services.AddTransient <IOperationMessageListener, ProtocolMessageListener>(); }
public GraphQLEngine(Func <System.Type, object> typeResolutionDelegate = null) { _constructor = new SchemaConstructor <ISchema, IGraphType>(_graphTypeAdapter, _typeResolver); _constructor.TypeResolutionDelegate = typeResolutionDelegate != null ? (Func <System.Type, object>)(type => typeResolutionDelegate(type) ?? CreateInstance(type)) : (Func <System.Type, object>)CreateInstance; }
public GraphQLEngine(Func <System.Type, object> typeResolutionDelegate = null, ITypeResolver typeResolver = null, IDocumentExecuter documentExecuter = null) { _documentExecutor = documentExecuter ?? new GraphQL.DocumentExecuter(); _typeResolver = typeResolver ?? _typeResolver; _constructor = new SchemaConstructor <ISchema, IGraphType>(_graphTypeAdapter, _typeResolver); _constructor.TypeResolutionDelegate = typeResolutionDelegate != null ? (Func <System.Type, object>)(type => typeResolutionDelegate(type) ?? CreateInstance(type)) : (Func <System.Type, object>)CreateInstance; }
protected ISchema Schema <TSchema>() { var typeAdapter = new GraphTypeAdapter(); var constructor = new SchemaConstructor <ISchema, IGraphType>(typeAdapter); var schema = constructor.Build(typeof(TSchema)); Assert.IsNotNull(schema); return(schema); }
public void Can_Ignore_Types_From_Unwanted_Namespaces() { var schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter()).Build( typeof(SchemaType1), typeof(SchemaType2), typeof(Unwanted.SchemaType3) ); schema.ShouldHaveQueries(4); schema.ShouldHaveMutations(2); schema.Query.ShouldHaveFieldWithName("foo"); schema.Query.ShouldHaveFieldWithName("bar"); schema.Query.ShouldHaveFieldWithName("baz"); schema.Query.ShouldHaveFieldWithName("bazIgnored"); schema.Mutation.ShouldHaveFieldWithName("updateSomething"); schema.Mutation.ShouldHaveFieldWithName("updateSomethingIgnored"); // Ignore all types from the 'Unwanted' namespace. var unwantedNamespaces = new[] { "GraphQL.Conventions.Tests.Builders.U", "GraphQL.Conventions.Tests.Builders.Un", "GraphQL.Conventions.Tests.Builders.Unw", "GraphQL.Conventions.Tests.Builders.Unwan", "GraphQL.Conventions.Tests.Builders.Unwant", "GraphQL.Conventions.Tests.Builders.Unwante", "GraphQL.Conventions.Tests.Builders.Unwanted" }; foreach (var namespaceStartFragment in unwantedNamespaces) { schema = new SchemaConstructor <ISchema, IGraphType>(new GraphTypeAdapter()) .IgnoreTypesFromNamespacesStartingWith(namespaceStartFragment) .Build( typeof(SchemaType1), typeof(SchemaType2), typeof(Unwanted.SchemaType3) ); schema.ShouldHaveQueries(3); schema.ShouldHaveMutations(1); schema.Query.ShouldHaveFieldWithName("foo"); schema.Query.ShouldHaveFieldWithName("bar"); schema.Query.ShouldHaveFieldWithName("baz"); schema.Query.ShouldNotHaveFieldWithName("bazIgnored"); schema.Mutation.ShouldHaveFieldWithName("updateSomething"); schema.Mutation.ShouldNotHaveFieldWithName("updateSomethingIgnored"); } }
public GraphQLEngine(Func <System.Type, object> typeResolutionDelegate = null) { _constructor = new SchemaConstructor <ISchema, IGraphType>(_graphTypeAdapter, _typeResolver); if (typeResolutionDelegate != null) { _typeResolver.DependencyInjector = new WrappedDependencyInjector(this, typeResolutionDelegate); _constructor.TypeResolutionDelegate = type => typeResolutionDelegate(type) ?? CreateInstance(type); } else { _constructor.TypeResolutionDelegate = type => _typeResolver?.DependencyInjector?.Resolve(type.GetTypeInfo()) ?? CreateInstance(type); } }