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

Test schema generation differs from normal schema generation #539

Open
GuySartorelli opened this issue Jun 21, 2023 · 0 comments
Open

Test schema generation differs from normal schema generation #539

GuySartorelli opened this issue Jun 21, 2023 · 0 comments

Comments

@GuySartorelli
Copy link
Member

There's some difference in building test schemas vs building real schemas which results in an error when building the below schema in tests which is perfectly fine and valid with normal runtime execution. This discrepancy is making it impossible to test #538 and could mean we are getting some false positives in existing tests.

Steps to reproduce

Create the following models.yml file in both vendor/silverstripe/graphql/tests/Schema/_testRecursiveSortSchemaCanBuild/models.yml and app/_graphql/models.yml:

SilverStripe\Security\Group:
  fields:
    '*': true

SilverStripe\Security\Permission:
  fields:
    id: true
    group: true
  operations:
    readOne: true
    read:
      plugins:
        sort:
          fields:
            id: true
            group:
              '*': true

Add this config to app/_config/graphql.yml:

SilverStripe\Control\Director:
  rules:
    'graphql': '%$SilverStripe\GraphQL\Controller.default'

SilverStripe\GraphQL\Schema\Schema:
  schemas:
    default:
      src:
        - app/_graphql

Add this method in vendor/silverstripe/graphql/tests/Schema/IntegrationTest.php:

public function testRecursiveSortSchemaCanBuild()
{
    // We're just testing that there's no exception on schema generation.
    $this->expectNotToPerformAssertions();

    $dir = '_' . __FUNCTION__;
    $this->createSchema(new TestSchemaBuilder([$dir]));
}

Finally, compare the results of running sake dev/graphql/build (which will run fine without any errors) vs running the new test method via PHPUnit.
The PHPUnit test will fail with this exception:

SilverStripe\GraphQL\Schema\Exception\SchemaBuilderException: Failed to apply plugin SilverStripe\GraphQL\Schema\DataObject\Plugin\QuerySort to readPermissions. Got error "Could not find field "id" on type "PermissionConnection". If it is a custom filter field, you will need to provide a resolver function in the "resolver" config for that field along with an explicit type."

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

1 participant