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

getTypeByName("JSON") doesn't always work in plugins #134

Closed
benjie opened this issue Dec 10, 2017 · 1 comment
Closed

getTypeByName("JSON") doesn't always work in plugins #134

benjie opened this issue Dec 10, 2017 · 1 comment
Labels
Milestone

Comments

@benjie
Copy link
Member

benjie commented Dec 10, 2017

Because it's only defined as-needed. This works as a substitute:

const JSONType = pgGetGqlTypeByTypeId("114");

e.g. the following code sample is broken by this:

https://www.graphile.org/postgraphile/extending/#adding-root-querymutation-fields

Potential solution I just hacked out - change PgTypesPlugin to define and register common types up front:

    // pgExtendedTypes might change what types we use for things
    const JSONType = pgExtendedTypes ? GraphQLJSON : SimpleJSON;
    const UUIDType = SimpleUUID; // GraphQLUUID
    const DateType = SimpleDate; // GraphQLDate
    const DateTimeType = SimpleDatetime; // GraphQLDateTime
    const TimeType = SimpleTime; // GraphQLTime

    // Other plugins might want to use JSON
    addType(JSONType);
    addType(UUIDType);
    addType(DateType);
    addType(DateTimeType);
    addType(TimeType);

    const oidLookup = {
      "20": stringType(
        "BigInt",
        "A signed eight-byte integer. The upper big integer values are greater then the max value for a JavaScript number. Therefore all big integers will be output as strings and not numbers."
      ), // bitint - even though this is int8, it's too big for JS int, so cast to string.
      "21": GraphQLInt, // int2
      "23": GraphQLInt, // int4
      "700": GraphQLFloat, // float4
      "701": GraphQLFloat, // float8
      "1700": GraphQLString, // numeric
      "790": GraphQLFloat, // money

      "1186": GQLInterval, // interval
      "1082": DateType, // date
      "1114": DateTimeType, // timestamp
      "1184": DateTimeType, // timestamptz
      "1083": TimeType, // time
      "1266": TimeType, // timetz

      "114": JSONType, // json
      "3802": JSONType, // jsonb
      "2950": UUIDType, // uuid

      "1560": GraphQLString, // bit
      "1562": GraphQLString, // varbit
    };

Potentially better solution is to register default types with getTypeByName function, allow overriding these with plugins.

Hat tip @syndesis

@benjie benjie added the bug label Dec 10, 2017
@benjie
Copy link
Member Author

benjie commented Dec 10, 2017

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

No branches or pull requests

1 participant