Skip to content

Help with Default Generic Wrappers #203

Open
@bentatham

Description

@bentatham

I am trying to use graphql-java-tools to wrap my vertx/reactivex with jooq application. For now, I'm trying to just use the default generic wrappers, so I convert all my reactivex Single's to Future, so in theory graphql-java-tools should be happy. But I still get:

Expected source object to be an instance of 'ca.nanometrics.halo.graphql.schema.Organization' but instead got 'io.reactivex.internal.observers.FutureSingleObserver' com.coxautodev.graphql.tools.ResolverError: Expected source object to be an instance of 'ca.nanometrics.halo.graphql.schema.Organization' but instead got 'io.reactivex.internal.observers.FutureSingleObserver'
(where FutureSingleObserver is a subclass of java.util.concurrent.Future)

My query class is defined as:

public class QueryResolver implements GraphQLQueryResolver
{
  private final Users m_users;
  private final Assets m_assets;

  @Inject
  QueryResolver(Users users, Assets assets)
  {
    m_users = users;
    m_assets = assets;
  }

  public Future<Organization> organization(int organizationId)
  {
    return m_users.getOrganizationById(organizationId).onErrorReturn(e -> {
      LOG.error("Error getting organization", e);
      return Optional.empty();
    }).map(optional -> optional.map(org -> new Organization(org, m_users, m_assets)).orElse(null))//
        .toFuture();
  }

Obviously, I need some better error handling in the code itself, but I'm just trying to make this work before moving forward.

My schema is created with the default generic wrappers:

    return com.coxautodev.graphql.tools.SchemaParser.newParser()//
        .file("halo-users.graphqls")//
        .dictionary(Organization.class) //
        .dictionary(Asset.class) //
        .dictionary(User.class) //
        .dictionary(AssetType.class) //
        .resolvers(//
            query //
        )//
        .options(SchemaParserOptions.newOptions()//
            .useDefaultGenericWrappers(true) //
            .build())//
        .build().makeExecutableSchema();

I can't find any good documentation on how I am supposed to do this, so perhaps I am missing something obvious? Based on #103 , it sounds like this should work. (Based on that issue, I should probably be able to get Single to work as well, although there seems to be no guidance on actually implementing the custom resolvers, but I'm happy to start with Future.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions