by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Richie Ward
@Rich43
Does anyone have an open source project that uses Spring Security and GraphQL?
asdfman777
@asdfman777
Hi, is there any reason why since com.graphql-java-kickstart:graphql-spring-boot-starter:7.0.0 the dependencies of org.springframework.boot:spring-boot-starter-websocket:2.2.6.RELEASE and org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE are now in runtime scope?
Michiel Oliemans
@oliemansm
@asdfman777 I think it happened by accident in this case by the gradle clean-up. Although it is something that's debatable I guess whether this library should explicitly import those starters (and more importantly specific versions of it) or if the user should import them themselves.
coderDem
@coderDem
@Rich43 here is a good example https://github.com/Blacktoviche/springboot-graphql-sqqr-jwt-demo but you need to update the code, that it works with the com.graphql-java-kickstart project
asdfman777
@asdfman777
@oliemansm I understand but it wasn't explicitly mentioned in release notes so I was a little bit surprised when my code stopped compiling. For now it's not a big deal, I just added what was missing. The question is will you change the scope back to "compile" for 7.0.X and then with release 7.1.0 use "runtime" with proper release notes?
Richie Ward
@Rich43
@coderDem Thanks for the example
Christian Ivicevic
@ChristianIvicevic

Greetings everyone, I am currently starting out with the kickstart libraries and was able to handle all the basic operations and use-cases. Now I am figuring out how to implement a server that adheres to the Relay server specification, namely the handling of nodes and have two issues that I need help with.

The documentation shows the Connection and SimpleListConnection classes with a (very) short example but I am doubting its correctness. Assume the SimpleListConnection would get a list of entities from a data source and returns the elements requested by the filter parameters. Since the cursors aren't actually deduced from the internal IDs of the entities but only the index in the list any mutation, be it adding or removing elements will cause the pagination to return odd results depending on which elements were manipulated or where an element has been added. Isn't it wrong to not generate the actual cursors based on the actual IDs of the entities?

My second question is slightly similar. I was curious whether I would have to manually write a resolver for the root query node and decode the ID myself to deduce which service to invoke in the first place. Isn't there any reasonable best practice using the library to simplify this?

If it makes a difference, I am currently trying out to work with the schema-first approach and not generating any schema in code.

Nicky Donna
@donnanicolas_twitter
Hello I need some help regarding testing resolvers
Max Berg
@mabgr_gitlab
hi any good rss feeds to recommend for graphql-java?
Ukonn Ra
@UkonnRa
Hi, anybody can give me a hand? graphql-java-kickstart/graphql-java-tools#400
Just wondering how to handle the field fetching in resolver...
Ukonn Ra
@UkonnRa
Sorry, just something wrong with my code, now fixed
Louis Steinthal
@lsteinth_gitlab
In DefaultGraphQLErrorHandler.processErrors() errors are filtered out (and replaced by general "Internal Server Error(s) while executing query") in order to hide implementation.
In our case, we don’t want to do that but instead have the errors exposed in the response.
Is there a way to override DefaultGraphQLErrorHandler.processErrors()?
Michiel Oliemans
@oliemansm
I'd start with enabling graphql.servlet.exception-handlers-enabled. That'll use the message of the exception itself instead of replacing everything with "Internal Server Error"
It also adds scanning for Springs @ExceptionHandler annotated methods that return GraphQLError or List<GraphQLError> if you want to return custom errors for (specific) exceptions.
Ukonn Ra
@UkonnRa
Hi, anybody knows how to add some custom fields into Connection/PageInfo when using relay? graphql-java/graphql-java#372
Michiel Oliemans
@oliemansm
@UkonnRa That's a GraphQL Java question, please raise that in their Spectrum channel instead
Ukonn Ra
@UkonnRa
Sure, thanks
Magnus Persson
@magnusp
I'm in a situation where I'm using reactors Flux/Mono in my resolvers. Now, I've spent a considerable amount of time googling on how to propagate parameter values from parent models and I have so far gathered that I can only consistently use ExecutionStepInfo and navigating one or more parents up to grab my variable. Is there any other way? I think I have seen some work being put into DataFetcher being able to return DataFetcherResult<Provider<...>> or Provider<DataFetcherResult<...>> to put stuff in localContext.
samoko85
@samoko85
Hello. I am developing a Jakarta EE application and using graphql-java-servletto expose a graphql endpoint. All is going well but, as mentioned in some other posts above, I am struggling with error handling. Datafetching errors are all mapped into 500 server errors by DefaultGraphQLErrorHandler. I would like to override this behaviour and provide more meaningful error messages to the client. How can I achieve this is a Java EE runtime?
coderDem
@coderDem
Hello @samoko85, you can create your own GraphqlError like : CustomException extends RuntimeException implements GraphQLError and throw them if something happens. Also you can activate the exception-handler with graphql.servlet.exception-handlers-enabled=true.

Fullcode: `public class CustomException extends RuntimeException implements GraphQLError {
private final int errorCode;

public CustomException(
        int errorCode,
        String errorMessage) {
    super(errorMessage);

    this.errorCode = errorCode;
}

@Override
public Map<String, Object> getExtensions() {
    Map<String, Object> customAttributes = new LinkedHashMap<>();

    customAttributes.put("errorCode", this.errorCode);
    customAttributes.put("errorMessage", this.getMessage());

    return customAttributes;
}

@Override
public List<SourceLocation> getLocations() {
    return Lists.newArrayList();
}

@Override
public ErrorType getErrorType() {
    return null;
}

}`

samoko85
@samoko85
Hey @coderDem thanks! I actually figure out already the GraphQLError way already last night. It works and for now I think is sufficient. The graphql.servlet.exception-handlers-enabled=true option I think it's not applicable for Java EE runtime but just for Spring Boot, is it?
coderDem
@coderDem
Hey @samoko85 , ok that is cool. I don't know. But you can also try to build an CustomGraphQLErrorHandler
 * Custom GraphQL error handler.
 */
@Component
public class CustomGraphQLErrorHandler implements GraphQLErrorHandler {

    @Override
    public List<GraphQLError> processErrors(List<GraphQLError> errors) {
        List<GraphQLError> clientErrors = errors.stream()
                .filter(this::isClientError)
                .collect(Collectors.toList());

        List<GraphQLError> serverErrors = errors.stream()
                .filter(e -> !isClientError(e))
                .collect(Collectors.toList());

        List<GraphQLError> errorList = new ArrayList<>();
        errorList.addAll(clientErrors);
        errorList.addAll(serverErrors);
        return errorList;
    }

    protected boolean isClientError(GraphQLError error) {
        return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable);
    }
}
samoko85
@samoko85
Interesting, but still, this is a spring component. I will see how to implement this as cdi or ejb bean
samoko85
@samoko85
Ok I think I have experimented enough with error handling and I am able to customise enough the graphql api response for my purposes
The only real thing missin for me at the moment is a way to avoid that the exception thrown ends up to print the stack trace in the std output. This is happening regardless from the exception type. I believe that after the error is translated into a GraphQLError type the exception is not catched and goes up in the stack.
Does anybody know a way to avoid this? This would ultimately mess up the logs of the server and that would have an impact on troubleshooting
I would love to have a mechanism to map a generic exception to a GraphQL Servelet Response (not GraphQLError) as it is done with ExceptionMapper<> in JAX-RS
samoko85
@samoko85
Am I dreaming?? :D
Jp-devs
@Jp-devs
Hi I'm a newbie to GraphQL when I used the latest Kickstart version and restart the server I get error like Error creating bean with name 'schemaParser' defined in class path resource [graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is java.lang.IllegalStateException: Could not resolve type variable 'org.springframework.data.domain.Persistable:ID' because declaring type is not parameterized: com.test.
Is there anything I am missing?
Removed the class name of my enterprise project
Jonathan Kupcho
@jkupcho

I'm a bit confused by this statement:

By default GraphQL tools uses the location pattern */.graphqls to scan for GraphQL schemas on the classpath. Use the schemaLocationPattern property to customize this pattern.

Do you still need to define a GraphQLSchema Bean in order to pick up the schema, or can you define your schema purely through *.graphqls files?

Michiel Oliemans
@oliemansm
You only have to define the files. The bean will then be created automatically.
Jonathan Kupcho
@jkupcho
Do you have a sample? I can't get it working at all.
Michiel Oliemans
@oliemansm
There are multiple sample projects inside the spring boot starter project and the separate samples project.
Jonathan Kupcho
@jkupcho
ah good call, I must have been blind, so I'm looking at it right now, is it because I didn't wire up the root Query object, possibly?
Michiel Oliemans
@oliemansm
Could be, don’t know your project obviously :) But you do need to expose classes representing your schema and implement GraphQLQueryResolver and such as shown in those projects.
Jonathan Kupcho
@jkupcho
:D
I'll try it later tonight, and let you know the result!
Jonathan Kupcho
@jkupcho
@oliemansm yep! just had to wire up a root query component, thanks Michiel!
coderDem
@coderDem
@oliemansm Hello, how it is possible to work as contributor? Because I want to try to update this https://github.com/graphql-java-kickstart/graphql-spring-boot/tree/master/altair-spring-boot-autoconfigure project, since the CDN part is not working for the newer version because it needs this part in the altair.html: <script> document.addEventListener('DOMContentLoaded', () => { AltairGraphQL.init(); }); </script>
Also the version is used is 2.1.7 and the newest released version is 2.4.11
Michiel Oliemans
@oliemansm
@coderDem You can follow the GitHub flow, there should be documentation online to find easily, its standard github workflow. You basically fork the project and create a PR back to this project with the fix. Then we’ll review and request changes or merge it. That’s basically it :) Any contribution is welcome, so thanks for helping out!
rajkumar1979
@rajkumar1979
Are there any implementations for cursor based pagination using dates in graphQL?
how can one override the cursor implementation using "@connection directive" , seems like this works only when all the records are in memory , does not get passed to the DB layer
coderDem
@coderDem
@oliemansm thank you I will try this out this week.