apache / apache/grails-core

Custom Data Fetcher in gorm-graphql 2.0.0 + MultiTenancy project - Fails Startup

Open
#14,500 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-graphql
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

heya - 2.0.0 looks really good and MultiTenancy support is definitely better - out of the box confirmed working with Database-Per-Tenant mappings too - so that's great.

Trying to add in a custom data fetcher when working in Multi-Tenancy mode seems to encounter a similar problem to v1 with static access at applicaiton startup:

`
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQL': Cannot resolve reference to bean 'graphQLSchema' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema': Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'generate' threw exception; nested exception is org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException: Tenant could not be resolved outside a web request`

The project works perfectly with the out-of-the-box config until we declare a custom fetcher (Simplified example):

static graphql = GraphQLMapping.lazy {
query('generalAlertBaseQuery', pagedResult(AlertBase)) {
defaultListArguments()
argument('qterm', String) {
nullable true
description "Left anchored alert name to search for"
}
dataFetcher(new PaginatedEntityDataFetcher>(AlertBase.gormPersistentEntity) {
@Override
protected DetachedCriteria buildCriteria(DataFetchingEnvironment environment) {
def q = new DetachedCriteria(AlertBase).build {
rlike('name',/${environment.getArgument('qterm')}/)
}
return q
}
})
}
}

This code is yanked directly from a v1 test rig, and I've only scanned over the updated 2.0.0 docs so apologies if I've missed something critical.

Is it possible that custom fetchers can be made to work in the multi-tenant setup? WIll try and update the test project to recreate this in a simple env.

Contributor guide

Open the contributing guide

Research direction

Start with the custom GraphQLMapping.lazy fetcher and the PaginatedEntityDataFetcher example in the issue, then reproduce the BeanCreationException with multi-tenancy enabled. Investigate why schema generation resolves a tenant outside a web request; done means custom fetchers start successfully in the multi-tenant configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, groovy
Domain
api, backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.