Giter VIP home page Giter VIP logo

Comments (2)

mfn avatar mfn commented on July 18, 2024 2

Switch to insomnia, and wait for it to do a schema request, you will see an error : Names must only contain [_a-zA-Z0-9] but "agenda.schedules_exceptions_exception" does not

Never heard of insomnia, but I can reproduce the same error using GraphiQL, e.g. using https://github.com/mll-lab/laravel-graphiql

{
  "errors": [
    {
      "message": "Names must only contain [_a-zA-Z0-9] but \"m.e\" does not.",

(is there a relation between the two, because the error is exactly the same?)

Anyway, I think the tooling to detect this is already possible: graphql-laravel is really just a (thin) layer on top of https://github.com/webonyx/graphql-php/ .

Your schema has a name, and in PHP code you can get the schema like this:
$schema = app('graphql')->schema('default');

This $schema is of type \GraphQL\Type\Schema and has a ->validate() method you can call: $errors = $schema->validate();, which returns an array of \GraphQL\Error\Error, if any:

array:1 [
  0 => GraphQL\Error\Error^ {#11569
    #message: "Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "m.e" does not."
    #code: 0
    #file: "./vendor/webonyx/graphql-php/src/Utils/Utils.php"

In an project of mine I've written an artisan command, part of the CI pipeline, which basically does exactly what I laid out:

    public function handle(): int
    {
        $schemaName = (string) $this->option('schema');

        $schema = app('graphql')->schema($schemaName);
        $result = $schema->validate();

        if ($result) {
            $this->error("Errors have been detected in the given GraphQL schema '$schemaName':");
            dump($result);

            return Kernel::RETURN_ERROR;
        }

        $this->info("No errors found in GraphQL schema '$schemaName");

        return Kernel::RETURN_SUCCESS;
    }

For performance reasons, such checks are not part of the runtime and have to be done out of band (the majority of schemas are "static", so one upfront validation run usually is enough).

from graphql-laravel.

phlisg avatar phlisg commented on July 18, 2024 1

Wow, thank you very much for your detailed answer, lots of useful insights on how to use the library differently.
I was actually looking how to "dynamically" load a schema based on export "channels" (i.e specific data endpoint for a specific frontend, like we have a "wordpress" channel in Laravel for our wordpress frontend), and also looking at multi-user access, which would load schemas and types from other definitions (maybe a Schema class).

I'll have some experiments and see how we can work with this information. Thanks again :)

For now I'll close the ticket but will update it if we have more info.

from graphql-laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.