ardatan / ardatan/graphql-tools

Cannot merge two directives if their descriptions differ (Part 2)

Open
#4,366 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

Description

This issue seems like a continuation of https://github.com/ardatan/graphql-tools/issues/3031 where merges conflict if descriptions differ.

We use **graphql-codegen** that uses **graphql-tools/merge** to combine schema. Schemas are generated by two tools: graphql-js and graphql-java. Both generate a directive that differs slightly in the description.

Example of the directive: [graphql-java/Directives.java at master · graphql-java/graphql-java · GitHub](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/Directives.java#L116)

```
/**
* The "specifiedBy" directive allows to provide a specification URL for a Scalar
*/
public static final GraphQLDirective SpecifiedByDirective = GraphQLDirective.newDirective()
.name(SPECIFIED_BY)
.description("Exposes a URL that specifies the behaviour of this scalar.")
.argument(newArgument()
.name("url")
.type(nonNull(GraphQLString))
.description("The URL that specifies the behaviour of this scalar."))
.validLocations(SCALAR)
.definition(SPECIFIED_BY_DIRECTIVE_DEFINITION)
.build();
```
The **node** parameter of the function **validateInputs()** in directives.ts looks like:
![image](https://user-images.githubusercontent.com/44408836/161838396-647207e9-0cb9-4a06-97fb-e991ab0e95d8.png)

The fix for issue 3031 does not handle the argument description.
Print out of "printedNode" and "existing PrintedNode" of **validateInputs()**:

![image](https://user-images.githubusercontent.com/44408836/161835071-2f445c9c-12d0-42a0-9810-7b3047cd24ea.png)

The "sameArguments " comparision fail due to the spelling difference of "behaviour".

**Expected behavior**

When I tweaked the the validateInputs() function locally to ignore the argument description, the graphql-codegen tool seemed to work properly.

**Environment:**

- `@graphql-tools/merge@8.2.6`:

Contributor guide

Open the contributing guide

Research direction

Start in directives.ts at validateInputs() and compare how directive arguments are checked when descriptions differ. Reproduce the graphql-codegen merge case using the graphql-js and graphql-java specifiedBy directive definitions, then verify that differing argument descriptions no longer cause a conflict while other argument differences still do.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.