[ 
https://issues.apache.org/jira/browse/CAMEL-12854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16788198#comment-16788198
 ] 

Hiram Chirino edited comment on CAMEL-12854 at 3/8/19 7:11 PM:
---------------------------------------------------------------

*Ideas*:

*1.* issuing a GraphQL query against an http GraphQL endpoint:
{code:java}
...to("graphql:http://theurl?query='{put{some(param){here}}}'&variable.param='value'")
{code}
 
 *2.* Setting up a GraphQL subscription
{code:java}
from("graphql:http://theurl?subscription='{put{some(param){here}}}'&variable.param='value'")
{code}
 

*3.* Perhaps hitting a GraphQL engine ( 
[https://github.com/graphql-java/graphql-java] ) directly.
{code:java}
// first register a graphql.GraphQL instance as mygraphqlbean 

...to("graphql:bean:mygraphqlbean?query='{put{some(param){here}}}'&variable.param='value'"){code}
 

*4.* Implementing GraphQL data fetchers with camel routes.  Something like:
{code:java}
// Implement a helper method to make it easy to attach a data fetch to given 
GraphQL field:
RuntimeWiring.Builder fetchWithCamel(final RuntimeWiring.Builder builder, 
String graphQLType , String graphQLField, CamelContext camelContext, String 
camelEndpoint) {
    final ProducerTemplate template = context.createProducerTemplate();
    builder.type(graphQLType, builder -> builder
        .dataFetcher(graphQLField, env->{
            return template.requestBody(endpoint, env);
        })
    );
    return builder;
}

// Then use it to create a GraphQL object:
final CamelContext context = ...
String schema = "type Query{hello: String}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);

RuntimeWiring.Builder builder = newRuntimeWiring()
fetchWithCamel(builder, "Query", "hello", context, "direct:hello")
RuntimeWiring runtimeWiring = builder.build();

SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = 
schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
GraphQL graphql = GraphQL.newGraphQL(graphQLSchema).build();
{code}
 

 


was (Author: chirino):
*Ideas*:

*1.* issuing a GraphQL query against an http GraphQL endpoint:
{code:java}
...to("graphql:http://theurl?query='{put{some(param){here}}}'&variable.param='value'")
{code}
 

*2.* Perhaps hitting a GraphQL engine ( 
[https://github.com/graphql-java/graphql-java] ) directly.
{code:java}
// first register a graphql.GraphQL instance as mygraphqlbean 

...to("graphql:bean:mygraphqlbean?query='{put{some(param){here}}}'&variable.param='value'"){code}
 

*3.* Implementing GraphQL data fetchers with camel routes.  Something like:
{code:java}
// Implement a helper method to make it easy to attach a data fetch to given 
GraphQL field:
RuntimeWiring.Builder fetchWithCamel(final RuntimeWiring.Builder builder, 
String graphQLType , String graphQLField, CamelContext camelContext, String 
camelEndpoint) {
    final ProducerTemplate template = context.createProducerTemplate();
    builder.type(graphQLType, builder -> builder
        .dataFetcher(graphQLField, env->{
            return template.requestBody(endpoint, env);
        })
    );
    return builder;
}

// Then use it to create a GraphQL object:
final CamelContext context = ...
String schema = "type Query{hello: String}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);

RuntimeWiring.Builder builder = newRuntimeWiring()
fetchWithCamel(builder, "Query", "hello", context, "direct:hello")
RuntimeWiring runtimeWiring = builder.build();

SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = 
schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
GraphQL graphql = GraphQL.newGraphQL(graphQLSchema).build();
{code}
 

 

> Provide a GraphQL component
> ---------------------------
>
>                 Key: CAMEL-12854
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12854
>             Project: Camel
>          Issue Type: New Feature
>            Reporter: Aurélien Pupier
>            Priority: Major
>              Labels: gsoc2019
>
> GraphQl is a growing and interesting technology https://graphql.org/learn/
> It is providing query language for API, it can be interesting to have it in 
> Camel.
> To investigate what would be interesting capabilities for it, created this 
> issue to gather ideas.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to