Search in sources :

Example 21 with Singleton

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();
}
Also used : Bean(io.micronaut.context.annotation.Bean) ResourceResolver(io.micronaut.core.io.ResourceResolver) GraphQL(graphql.GraphQL) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) Factory(io.micronaut.context.annotation.Factory) GraphQLSchema(graphql.schema.GraphQLSchema) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Singleton(jakarta.inject.Singleton) SchemaGenerator(graphql.schema.idl.SchemaGenerator) BufferedReader(java.io.BufferedReader) InputStreamReader(java.io.InputStreamReader) InputStreamReader(java.io.InputStreamReader) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) BufferedReader(java.io.BufferedReader) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 22 with Singleton

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();
}
Also used : GraphQLSchema(graphql.schema.GraphQLSchema) SchemaParserBuilder(graphql.kickstart.tools.SchemaParserBuilder) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 23 with Singleton

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();
}
Also used : Bean(io.micronaut.context.annotation.Bean) ResourceResolver(io.micronaut.core.io.ResourceResolver) GraphQL(graphql.GraphQL) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) Factory(io.micronaut.context.annotation.Factory) GraphQLSchema(graphql.schema.GraphQLSchema) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Singleton(jakarta.inject.Singleton) SchemaGenerator(graphql.schema.idl.SchemaGenerator) BufferedReader(java.io.BufferedReader) InputStreamReader(java.io.InputStreamReader) InputStreamReader(java.io.InputStreamReader) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) BufferedReader(java.io.BufferedReader) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 24 with Singleton

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();
}
Also used : ResourceResolver(io.micronaut.core.io.ResourceResolver) GraphQL(graphql.GraphQL) ExtendedScalars(graphql.scalars.ExtendedScalars) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) Singleton(jakarta.inject.Singleton) InputStreamReader(java.io.InputStreamReader) Bean(io.micronaut.context.annotation.Bean) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaParser(graphql.schema.idl.SchemaParser) Factory(io.micronaut.context.annotation.Factory) GraphQLSchema(graphql.schema.GraphQLSchema) SchemaGenerator(graphql.schema.idl.SchemaGenerator) BufferedReader(java.io.BufferedReader) InputStreamReader(java.io.InputStreamReader) RuntimeWiring(graphql.schema.idl.RuntimeWiring) SchemaGenerator(graphql.schema.idl.SchemaGenerator) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) BufferedReader(java.io.BufferedReader) SchemaParser(graphql.schema.idl.SchemaParser) GraphQLSchema(graphql.schema.GraphQLSchema) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 25 with Singleton

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;
}
Also used : NewRelicRegistry(com.newrelic.telemetry.micrometer.NewRelicRegistry) NamedThreadFactory(io.micrometer.core.instrument.util.NamedThreadFactory) Attributes(com.newrelic.telemetry.Attributes) Singleton(jakarta.inject.Singleton)

Aggregations

Singleton (jakarta.inject.Singleton)26 Bean (io.micronaut.context.annotation.Bean)7 Factory (io.micronaut.context.annotation.Factory)6 Properties (java.util.Properties)6 GraphQLSchema (graphql.schema.GraphQLSchema)5 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 GraphQL (graphql.GraphQL)4 RuntimeWiring (graphql.schema.idl.RuntimeWiring)4 SchemaGenerator (graphql.schema.idl.SchemaGenerator)4 SchemaParser (graphql.schema.idl.SchemaParser)4 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)4 ResourceResolver (io.micronaut.core.io.ResourceResolver)4 Named (jakarta.inject.Named)4 Test (org.junit.Test)3 ConfiguredStreamBuilder (io.micronaut.configuration.kafka.streams.ConfiguredStreamBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Arrays (java.util.Arrays)2 Locale (java.util.Locale)2 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)2