Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate GraphQL Typesafe Client into QuarkusTest #26365

Closed
t1 opened this issue Jun 25, 2022 · 5 comments · Fixed by #26979
Closed

Integrate GraphQL Typesafe Client into QuarkusTest #26365

t1 opened this issue Jun 25, 2022 · 5 comments · Fixed by #26979
Assignees
Milestone

Comments

@t1
Copy link

t1 commented Jun 25, 2022

Description

I'd like to directly inject a GraphQL Client into a test, i.e.:

@QuarkusTest
class UserTest {

    @GraphQLClientApi interface Api {
        @Query User user(int id);
    }

    public static class User {
        String name;
    }

    @Inject Api api;

    @Test void shouldGetJane() {
        var jane = api.user(1);

        then(jane.name).isEqualTo("Jane");
    }
}

But then I get a RuntimeException: "URL not configured for client."

The workaround I have to use is:

    @TestHTTPResource("graphql")
    URI uri;

    Api api() {return TypesafeGraphQLClientBuilder.newBuilder().endpoint(uri).build(Api.class);}

    @Test void shouldGetJane() {
        var jane = api().user(1);

        then(jane.name).isEqualTo("Jane");
    }
}

Implementation ideas

No response

@t1 t1 added the kind/enhancement New feature or request label Jun 25, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 25, 2022

/cc @jmartisk, @phillip-kruger

@jmartisk
Copy link
Contributor

And do you have the URL configured somewhere? To have the client point at the testing Quarkus instance, your application.properties will need something like

%test.quarkus.smallrye-graphql-client.CLIENT_CONFIG_KEY.url=http://localhost:${quarkus.http.test-port:8081}/graphql

@t1
Copy link
Author

t1 commented Jun 27, 2022

That would be another workaround, but as it works out-of-the-box with the MP REST Client, it would be nice to have this for GraphQL as well.

@t1
Copy link
Author

t1 commented Jun 27, 2022

and I suppose the change could be rather miniscule.

@jmartisk
Copy link
Contributor

Oh, right, now I understand your request. And it makes sense. We could automatically fill the url property when runmode=test AND it's not defined explicitly.
I can look into it when I get some spare cycles (but of course, PR contributions are welcome :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants