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

subgraph-js: directive can't be used on custom scalar definition #2882

Open
velias opened this issue Dec 7, 2023 · 0 comments
Open

subgraph-js: directive can't be used on custom scalar definition #2882

velias opened this issue Dec 7, 2023 · 0 comments

Comments

@velias
Copy link

velias commented Dec 7, 2023

We need to add @tag directive on custom scalar in our subgraph schema to control contracts, unfortunately it disappears during the subgraph schema generation (we call buildSubgraphSchema() with typeDefs and resolvers provided). It happens only if resolver for that custom scalar type is also added. Without the resolver directive is present in the final schema.

Whole astNode looks to be removed from the custom scalar type during schema build.
I trace problem down to this code in the addResolversToSchema method.

for (const fn in fieldConfigs) {

I'm not fully sure what is this code doing/copiing, but what helped me is to prevent astNode to be copied if it is empty:

if (isScalarType(type)) {
    for (const fn in fieldConfigs) {
        // CUSTOMIZATION: skip astNode copying if empty to keep directives etc on the scalar type definition
        if (fn != "astNode" || (fieldConfigs as any)[fn])
            (type as any)[fn] = (fieldConfigs as any)[fn];
    }
}
@velias velias changed the title Directive can't be used on custom scalar definition subgraph-js: directive can't be used on custom scalar definition Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant