0

I am having some issues trying to mock the smallrye-graphql-client in my unit tests. I thought it would be a process similar to mocking the RestClient https://github.com/quarkusio/quarkus/issues/9630 but it doesn't work that way.

GraphQL client:

@GraphQLClientApi(configKey = "graphql-client")
public interface SomeGraphQLClient {
    @Query("accounts")
    List<Account> getAccounts();
}

Test:

@QuarkusTest
public final class SomeGraphQLClientTest {
    @InjectMock()
    SomeGraphQLClient client;

    @BeforeEach
    void setup() {
        when(client.getAccounts()).thenReturn(... list of accounts...);
    }

    @Test
    public void someTest() {
        ...
    }
}

application.yaml

  ...
  smallrye-graphql-client:
    graphql-client:
      url: http://localhost:8081/graphql

Error message:

Invalid use of io.quarkus.test.junit.mockito.InjectMock - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton.

How can I mock the smallrye-graphql-client in Quarkus?

Thank you in advance for your help

  • I admit in Quarkus team we haven't really thought about this yet. Support for mocking of injected GraphQL clients will probably need some code changes. For the time being, would you be able to do this without injecting pre-configured clients, but instead build your own mocks manually, using `Mockito.mock(SomeGraphQLClient.class)` and so? – Jan Martiška Mar 02 '22 at 10:05
  • I already did that and I went a little further... Now I am testing a mutation and I am getting `Query failed to validate` – from_tel Mar 02 '22 at 22:00

0 Answers0