Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM Graphql Java

Avatar

Community Advisor

Hi Community,

 

I am trying to create a graphQl endpoint using the https://www.graphql-java.com/documentation/getting-started/ .

 

So I'll be writing this sample code in Servlet and trying to print the same response {hello=world} using the Servlet endpoint.

But when I am adding the dependency, the bundle is never active when I run the core maven build and always fails during the full build.

Could you help me with what I am missing here?

Thank you,

Prince

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Strangely, I don't have any compile issues.
Could you help me with what changes you made in core pom for the BND plugin?

View solution in original post

9 Replies

Avatar

Community Advisor

@Prince_Shivhare Can you please share build error and list of packages not getting resolved in bundle. 

Please confirm you are trying to add below dependency in code.

<dependency>
    <groupId>com.graphql-java</groupId>
    <artifactId>graphql-java</artifactId>
    <version>20.2</version>
</dependency>

Avatar

Community Advisor

It's an error of some dependent jars in a graphql-java.
If you'll try to setup the same and use the example Java code provided in the link. you'll see the error during the build.

Avatar

Community Advisor

@Prince_Shivhare I got compilation error and after changing below code it fixed the issue and build failure also did not come. 

RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
                .type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world")))
                .build();

 For bundle to be active, you need to embed the graphql jar in BND plugin to resolve import issues.

Avatar

Correct answer by
Community Advisor

Strangely, I don't have any compile issues.
Could you help me with what changes you made in core pom for the BND plugin?

Avatar

Level 2

Hi @Prince_Shivhare 

I'm also facing the same issue. Could you please provide me the steps if you already fix it?

 

Thank you!

Avatar

Community Advisor

@Lakshmi99 ,

 

Could you please help me with your usecase?

Avatar

Level 2

Hi @Prince_Shivhare 

Use case: Expose content fragments data using servlet through graphql. 

Trying sample code in the link above but getting many dependency issues fir the below. Tried to resolve but no luck.

import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import graphql.schema.StaticDataFetcher;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;

public class GQLService {

public static void main(String[] args) {
String schema = "type Query{hello: String}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring()
.type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world")))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult executionResult = build.execute("{hello}");
System.out.println(executionResult.getData().toString());
// Prints: {hello=world}
}
}

 

 

Thank you

Avatar

Community Advisor

If you don't have any specific parameter requirement, you can go ahead with out-of-the-box graphql implementation with content fragments.

 

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...