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

--no-database schema build fails with various module configuration #445

Open
1 task
maxime-rainville opened this issue Feb 15, 2022 · 2 comments
Open
1 task

Comments

@maxime-rainville
Copy link
Contributor

The schema builder tries to run a bunch of queries for the versions key on versionned DataObjects.

Normally, that's fine ... however if you're trying to build your schema with the NullDatabase, it's going to crash because Versionned::allVersions() always tries to run a bunch of queries.

I'm tempted to call this a bug with Versionned. But I'm not sure if it's indicative of a wider problem with GraphQL v4. There's a big catch statement on the Builder that was being triggered by this issue. That block prints out a warning saying "Your schema configuration requires access to the database", which implies that there might be a legitimate use case for being able to run queries when bulidng a schema.

} catch (NullDatabaseException $e) {
$candidate = null;
foreach ($e->getTrace() as $item) {
$class = $item['class'] ?? null;
$function = $item['function'] ?? null;
// This is the only known path to a database query, so we'll offer some help here.
if ($class === FieldAccessor::class && $function === 'accessField') {
$candidate = $item;
break;
}
}
$logger->warning("
Your schema configuration requires access to the database. This can happen
when you add fields that require type introspection (i.e. custom getters).
It is recommended that you specify an explicit type when adding custom getters
to your schema.");
if ($candidate) {
$logger->warning(sprintf(
"
This most likely happened when you tried to add the field '%s' to '%s'",
$candidate['args'][1],
get_class($candidate['args'][0])
));
}
throw $e;
}

Also, the logger on line 115 throws an error because the $candidate array is not in the expected format.

Pull requests

@maxime-rainville maxime-rainville changed the title Versionned crashes no DB schema build --no-database schema build fails with various module configuration Feb 15, 2022
@maxime-rainville
Copy link
Contributor Author

Just did a bit more investigations. Even after we fix the Versionned problem, we're still seeing failures from Fluent, AkismetMiddleware and Subsites.

Those three modules could potentially break a dev/build because they want to run queries on every requests. They all have logic to try to detect if specific tables exists on the DB. To make things even more fun, they all use different combination of approaches:

Even if we patch all of those to account for the NullDatabase use case, we'll probably end up breaking other people code.

@maxime-rainville maxime-rainville self-assigned this Feb 16, 2022
@GuySartorelli
Copy link
Member

GuySartorelli commented Feb 16, 2022

@maxime-rainville That reminds me about silverstripe/silverstripe-framework#10041 - if that PR would be useful to help clean this up let me know and I'll take a look at seeing what went wrong with those tests.

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

No branches or pull requests

2 participants