Description
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
- 1. The issue provides a reproduction available on
Github,
Stackblitz
or
CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure Mesh package versions under
package.json
matches yours.
- 2. A failing test has been provided
- 3. A local solution has been provided
- 4. A pull request is pending review
Describe the bug
The OmniGraph-OpenAPI library cannot deep merge objects listed in an allOf
operator.
For a component combining properties of different objects via the allOf
keyword, if any property of these objects exists in more than one of them and this property is also an object, then these object-like overlapping properties will not be merged into one single object, combining all their different sub-properties. Instead, only the sub-properties of the last object-like overlapping property will be included in the resulting object.
A more detailed example of the issue has been added here.
To Reproduce Steps to reproduce the behavior:
- Using the
loadGraphQLSchemaFromOpenAPI
function from the@omnigraph/openapi
library, load a schema containing objects listed in anallOf
operator with overlapping properties (e.g.: https://github.com/cweckesser/graphql-mesh-testing/blob/main/packages/loaders/openapi/graphql/schemas/test-schema.json, here theattributes
property is defined in two objects). - Once the schema is loaded, either:
- inspect it using debugging tools,
- log it to the console or
- launch a GraphQL server (e.g. GraphQL Yoga) and then analyze the response from the introspection query
- In either case, only the overlapping property of the last object listed in the
allOf
operator will be in the resulting schema
For an already-working example that reproduces this issue, consider the following code sandbox
Alternatively, the following repository can be checked out and then the following instructions can be followed:
- From the project root folder, move to the sub-directory for the OpenAPI loader:
cd packages/loaders/openapi
- Build the project:
yarn
- Test the schema generation by either:
- executing unit tests:
yarn test:unit
- launching a GraphQL Yoga server and check the introspection result:
yarn start
Expected behavior
The overlapping properties of objects listed in an allOf
operator should be deep merged. Consider the following example:
"Person": {
"data": {
"allOf": [{
"attributes": {
"description": "Address fields",
"properties": {
"street_name": { "type": "string" },
"street_number": { "type": "string" },
"postal_code": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" },
"country": { "type": "string" }
}
}
}, {
"attributes": {
"description": "Contact fields",
"properties": {
"personal_email": { "type": "string" },
"work_email": { "type": "string" },
"personal_phone_number": { "type": "string" },
"work_phone_number": { "type": "string" }
}
}
}]
}
}
When processing this schema, it should be expected that the Person.data.attributes
sub-property resulted in the combination of all the attributes
object-properties corresponding to the objects listed in the allOf
operator:
{
"Person": {
"data": {
"attributes": {
"street_name": {...},
"street_number": {...},
"postal_code": {...},
"city": {...},
"state": {...},
"country": {...},
"personal_email": {...},
"work_email": {...},
"personal_phone_number": {...},
"work_phone_number": {...}
}
}
}
}
Environment:
- OS: macOS
- "@omnigraph/openapi": "^0.94.6",
- NodeJS: 16
Additional context