Skip to content

Add end-to-end integration test for @nonExposed decorator #701

@javiertoledo

Description

@javiertoledo

Summary

The @nonExposed decorator lacks an end-to-end integration test that verifies fields marked as non-exposed are actually excluded from the generated GraphQL schema.

Current State

  • Unit tests verify that @nonExposed correctly registers field names in config.nonExposedGraphQLMetadataKey
  • Tests cover @Entity, @ReadModel, @Command, and @Query class decorators
  • However, the GraphQL generator tests stub out internals, so we don't have a test that:
    1. Defines a class with @nonExposed fields
    2. Generates the actual GraphQL schema
    3. Asserts the non-exposed fields are NOT present in the schema

Proposed Solution

Add an integration test that:

it('excludes @nonExposed fields from generated GraphQL schema', () => {
  @ReadModel({ authorize: 'all' })
  class TestReadModel {
    @field(type => UUID)
    public readonly id!: UUID

    @field()
    public readonly publicField!: string

    @nonExposed
    @field()
    public readonly secretField!: string
  }

  // Register the read model in config
  // Generate the GraphQL schema
  const schema = GraphQLGenerator.generateSchema(config)
  
  // Get the TestReadModel type from schema
  const testReadModelType = schema.getType('TestReadModel') as GraphQLObjectType
  const fields = testReadModelType.getFields()

  // Assert secretField is NOT in the schema
  expect(fields['publicField']).to.exist
  expect(fields['secretField']).to.be.undefined
})

Context

This was identified while fixing a timing bug in @nonExposed (commit ef27cb9). The fix is architecturally sound and follows the same pattern as @sequencedBy, but an integration test would provide additional confidence.

Files to Consider

  • packages/core/test/services/graphql/graphql-generator.test.ts
  • packages/core/test/services/graphql/graphql-query-generator.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions