Graphback: Directives on field definitions are removed if there is a @oneToOne annotation

Created on 29 Jul 2020  路  10Comments  路  Source: aerogear/graphback

I'm not sure how general the problem is here, but in my generated schema for one of my fields with the following annotation:

    """
    @oneToOne(key: 'company_id')
    """

the schema directives for that field in my model schema are removed in the generated schema.

bug

Most helpful comment

Yep. I think that issue is simply that buildRelationshipFilterFieldMap should use GraphQL-Compose.
As quick hack adding

astNode: modelFields[current.ownerField.name].astNode

to
https://github.com/aerogear/graphback/blob/master/packages/graphback-core/src/relationships/relationshipHelpers.ts#L121:L121

solves the problem.
We can either refactor this method or hack it (we are missing only directives here as the rest of the elements are handled by fields itself)

All 10 comments

It does seem to generally be a problem with all fields that have annotations, all of my directives are removed in the generated schema, that I've seen so far.

I need this fixed ASAP and am happy to do a PR, but seems like this is probably a problem with graphql-compose?

https://github.com/graphql-compose/graphql-compose/issues/273 logged.
Looking for alternatives that will make this work in upcoming days.

@lastmjs What version of GraphQL you are using? 0.15?

I am using 14.6.0

I don't believe this issue relates to https://github.com/graphql-compose/graphql-compose/issues/273 since it appears to only be happening on the @oneToOne and @oneToMany annotated fields (it maps just fine with other or no field annotations.

I will take a look into it now, but with timezone differences (reaching end of day where I am) you may be able to get to it first @lastmjs, if its urgent for you.

If it can be done in the next 2-3 days, I'll let you handle it, I think that would be quicker. I do have a workaround in the short-term

ah.. it could be that we do update these fields in schema plugin ourselves and this removes directive.
A possible place that can fail here:
https://github.com/aerogear/graphback/blob/master/packages/graphback-codegen-schema/src/SchemaCRUDPlugin.ts#L154-L158

Since we want to make sure @lastmjs is going to be successful on our platform I tried to figure out the problem and I think this is due to fields being overridden by our generated fields in (buildRelationshipFilterFieldMap).

Quick test confirms that original model has directive.

console.log(model.graphqlType.astNode?.directives)

Yep. I think that issue is simply that buildRelationshipFilterFieldMap should use GraphQL-Compose.
As quick hack adding

astNode: modelFields[current.ownerField.name].astNode

to
https://github.com/aerogear/graphback/blob/master/packages/graphback-core/src/relationships/relationshipHelpers.ts#L121:L121

solves the problem.
We can either refactor this method or hack it (we are missing only directives here as the rest of the elements are handled by fields itself)

Fix should be available now in 0.15.1

https://github.com/aerogear/graphback/releases/tag/0.15.1

Was this page helpful?
0 / 5 - 0 ratings