use of jakarta.inject.Singleton in project micronaut-graphql by micronaut-projects.
the class GraphQLFactory method graphQL.
@Bean
@Singleton
public GraphQL graphQL(ResourceResolver resourceResolver, ToDosDataFetcher toDosDataFetcher, CreateToDoDataFetcher createToDoDataFetcher, CompleteToDoDataFetcher completeToDoDataFetcher, DeleteToDoDataFetcher deleteToDoDataFetcher, AuthorDataFetcher authorDataFetcher) {
SchemaParser schemaParser = new SchemaParser();
SchemaGenerator schemaGenerator = new SchemaGenerator();
// Parse the schema.
TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader(resourceResolver.getResourceAsStream("classpath:schema.graphqls").get()))));
// Create the runtime wiring.
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", typeWiring -> typeWiring.dataFetcher("toDos", toDosDataFetcher)).type("Mutation", typeWiring -> typeWiring.dataFetcher("createToDo", createToDoDataFetcher).dataFetcher("completeToDo", completeToDoDataFetcher).dataFetcher("deleteToDo", deleteToDoDataFetcher)).type("ToDo", typeWiring -> typeWiring.dataFetcher("author", authorDataFetcher)).build();
// Create the executable schema.
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
// Return the GraphQL bean.
return GraphQL.newGraphQL(graphQLSchema).build();
}
use of jakarta.inject.Singleton in project micronaut-graphql by micronaut-projects.
the class GraphQLFactory method graphQL.
@Bean
@Singleton
public GraphQL graphQL(ToDoQueryResolver toDoQueryResolver, ToDoMutationResolver toDoMutationResolver, ToDoResolver toDoResolver) {
// Parse the schema.
SchemaParserBuilder builder = SchemaParser.newParser().file("schema.graphqls").resolvers(toDoQueryResolver, toDoMutationResolver, toDoResolver);
// Create the executable schema.
GraphQLSchema graphQLSchema = builder.build().makeExecutableSchema();
// Return the GraphQL bean.
return GraphQL.newGraphQL(graphQLSchema).build();
}
use of jakarta.inject.Singleton in project micronaut-graphql by micronaut-projects.
the class GraphQLFactory method graphQL.
@Bean
@Singleton
public GraphQL graphQL(ResourceResolver resourceResolver, CurrentUserDataFetcher currentUserDataFetcher, LoginDataFetcher loginDataFetcher) {
SchemaParser schemaParser = new SchemaParser();
SchemaGenerator schemaGenerator = new SchemaGenerator();
// Parse the schema.
TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader(resourceResolver.getResourceAsStream("classpath:schema.graphqls").get()))));
// Create the runtime wiring.
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", typeWiring -> typeWiring.dataFetcher("currentUser", currentUserDataFetcher)).type("Mutation", typeWiring -> typeWiring.dataFetcher("login", loginDataFetcher)).build();
// Create the executable schema.
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
// Return the GraphQL bean.
return GraphQL.newGraphQL(graphQLSchema).build();
}
use of jakarta.inject.Singleton in project micronaut-graphql by micronaut-projects.
the class GraphQLFactory method graphQL.
@Bean
@Singleton
public GraphQL graphQL(ResourceResolver resourceResolver, MessagesDataFetcher messagesDataFetcher, ChatDataFetcher chatDataFetcher, StreamDataFetcher streamDataFetcher) {
SchemaParser schemaParser = new SchemaParser();
SchemaGenerator schemaGenerator = new SchemaGenerator();
// Parse the schema.
TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
resourceResolver.getResourceAsStream("classpath:schema.graphqls").ifPresent(s -> typeRegistry.merge(schemaParser.parse(new BufferedReader(new InputStreamReader(s)))));
// Create the runtime wiring.
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().scalar(ExtendedScalars.DateTime).type("QueryRoot", typeWiring -> typeWiring.dataFetcher("messages", messagesDataFetcher)).type("MutationRoot", typeWiring -> typeWiring.dataFetcher("chat", chatDataFetcher)).type("SubscriptionRoot", typeWiring -> typeWiring.dataFetcher("stream", streamDataFetcher)).build();
// Create the executable schema.
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
// Return the GraphQL bean.
return GraphQL.newGraphQL(graphQLSchema).build();
}
use of jakarta.inject.Singleton in project micronaut-micrometer by micronaut-projects.
the class NewRelicTelemetryMeterRegistryFactory method newRelicRegistry.
/**
* Create a NewRelicRegistry bean if global metrics are enables
* and the newrelic is enabled. Will be true by default when this
* configuration is included in project.
*
* @param config The the new relic config
* @return A NewRelicRegistry
*/
@Singleton
NewRelicRegistry newRelicRegistry(NewRelicRegistryConfig config) throws UnknownHostException {
NewRelicRegistry newRelicRegistry = NewRelicRegistry.builder(config).commonAttributes(new Attributes().put("host", InetAddress.getLocalHost().getHostName())).build();
newRelicRegistry.config().meterFilter(MeterFilter.ignoreTags("plz_ignore_me"));
newRelicRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("jvm.threads"));
newRelicRegistry.start(new NamedThreadFactory("newrelic.micrometer.registry"));
return newRelicRegistry;
}
Aggregations