question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introspector does not differentiate between enums of different schemas

See original GitHub issue

Problem

If a Postgres column uses the type test.status, the introspector simply infers it as status, so enum name collisions are possible.

import { Kysely, sql } from 'kysely';

const up = async (db: Kysely<any>) => {
  await db.transaction().execute(async (trx) => {
    await trx.schema
      .createSchema('test')
      .ifNotExists()
      .execute();

    await trx.schema
      .withSchema('test')
      .createType('status')
      .asEnum(['FOO', 'BAR'])
      .execute();

    await trx.schema
      .createType('status')
      .asEnum(['CONFIRMED', 'UNCONFIRMED'])
      .execute();

    await trx.schema
      .createTable('users')
      .addColumn('user_status', sql`status`)
      .addColumn('user_status_2', sql`test.status`)
      .execute();
  });
};

// Introspection result:
[{
  {
    dataType: 'status',
    enumValues: null,
    hasDefaultValue: false,
    isAutoIncrementing: false,
    isNullable: true,
    name: 'user_status',
  },
  {
    dataType: 'status',
    enumValues: null,
    hasDefaultValue: false,
    isAutoIncrementing: false,
    isNullable: true,
    name: 'user_status_2',
  },
}]

Possible solutions

  • Include the schema in the data type (feels like a scary/breaking change): dataType: 'test.status'
  • Add a schema property: dataTypeSchema: 'public'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
koskimascommented, Nov 5, 2022

@RobinBlomberg This will be implemented in the next release. All postgres columns have the new dataTypeSchema field set. The default value is pg_catalog which is the schema of all built-in postgres types.

2reactions
koskimascommented, Sep 29, 2022

I’d say dataTypeSchema is better

Read more comments on GitHub >

github_iconTop Results From Across the Web

enums are broken after transformSchema · Issue #1056 - GitHub
This happens for every other enum in my schema. So there's evidently some difference between the original schema and the returned value from ......
Read more >
How to Query Enums with GraphQL using Introspection
Introspection allows you to ask a GraphQL schema for information about what queries it supports. In the introspection system, there are 6 ...
Read more >
What is the difference between enum and example in ...
The swagger schema validation is not differentiating between enum and example, i.e. if I add a value other than enum values, still the...
Read more >
Apollo Federation subgraph specification
The returned schema string includes all uses of federation-specific directives, such as @key . The built-in introspection query's response does not include ...
Read more >
Combining Schemas – GraphQL Tools
schema : this is a non-executable schema representing the remote API. The remote schema may be obtained using introspection, or fetched as a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found