Skip to content

@graphile/simplify-inflection not using _schemaPrefix #2410

Open
@danzho

Description

@danzho

Summary

(for v5)

@graphile/simplify-inflection seems to ignore _schemaPrefix.

Steps to reproduce

Here's a plugin that prefixes anything in the foo pg schema with foo_: https://gist.githubusercontent.com/danzho/fce5e8905c06745fb434e1f3a7530ba3/raw/6814300c61d20729af668c9803b5fb0155ed797a/foo-prefix-plugin.ts

With vanilla v5, this works as expected: foo.user -> FooUser. allUsers -> allFooUsers.

However, when you then add the @graphile/simplify-inflection inflector, single-/many-relation queries lose their schema prefix.

Expected results

fooUser {
    fooKids
    fooEmployer
}

Actual results

fooUser {
    kids
    employer
}

Additional context

I could fix this for my needs by overriding singleRelation and _manyRelation to return this.camelCase(relation.remoteResource.name) since relation.remoteResource.name returns schema-prefixed values like "foo_user".

Also, interestingly some relationships are correctly prefixed. In this case, a compound (currency_id, store_id) fk relation:

fooUser {
    fooCurrencyByCurrencyIdAndStoreId # <-- 
    fooKidsByUserId
    fooEmployerByEmployerId
}

Became this when using @graphile/simplify-inflection:

fooUser {
    fooCurrency # <--
    kids
    employer
}

(It stands out since it's the only one with the correct behavior, so there might be a special case that's accidentally working in the current impl)

Also I was sent here from discord: https://discord.com/channels/489127045289476126/498852330754801666/1349098001343189043

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    🌳 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions