@graphql-mesh/thrift 0.95.2 → 0.95.3-alpha-20230901115903-82e6f6069
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +21 -24
- package/esm/index.js +21 -24
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -389,8 +389,6 @@ class ThriftHandler {
|
|
|
389
389
|
break;
|
|
390
390
|
case thrift_parser_1.SyntaxType.StructDefinition: {
|
|
391
391
|
const description = processComments(statement.comments);
|
|
392
|
-
const objectFields = {};
|
|
393
|
-
const inputObjectFields = {};
|
|
394
392
|
const structTypeVal = {
|
|
395
393
|
id: Math.random(),
|
|
396
394
|
name: typeName,
|
|
@@ -399,37 +397,36 @@ class ThriftHandler {
|
|
|
399
397
|
};
|
|
400
398
|
topTypeMap[typeName] = structTypeVal;
|
|
401
399
|
const structFieldTypeMap = structTypeVal.fields;
|
|
400
|
+
const fields = [];
|
|
402
401
|
for (const field of statement.fields) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const description = processComments(field.comments);
|
|
407
|
-
const processedFieldTypes = getGraphQLFunctionType(field.fieldType, field.fieldID?.value);
|
|
408
|
-
fieldOutputType = processedFieldTypes.outputType;
|
|
409
|
-
fieldInputType = processedFieldTypes.inputType;
|
|
410
|
-
if (field.requiredness === 'required') {
|
|
411
|
-
fieldOutputType = new graphql_1.GraphQLNonNull(fieldOutputType);
|
|
412
|
-
fieldInputType = new graphql_1.GraphQLNonNull(fieldInputType);
|
|
413
|
-
}
|
|
414
|
-
objectFields[fieldName] = {
|
|
415
|
-
type: fieldOutputType,
|
|
416
|
-
description,
|
|
417
|
-
};
|
|
418
|
-
inputObjectFields[fieldName] = {
|
|
419
|
-
type: fieldInputType,
|
|
420
|
-
description,
|
|
421
|
-
};
|
|
422
|
-
structFieldTypeMap[fieldName] = processedFieldTypes.typeVal;
|
|
402
|
+
fields.push({ field, description: processComments(field.comments) });
|
|
403
|
+
const { typeVal } = getGraphQLFunctionType(field.fieldType, field.fieldID?.value);
|
|
404
|
+
structFieldTypeMap[field.name.value] = typeVal;
|
|
423
405
|
}
|
|
406
|
+
const getFieldsMap = (typeKind) => Object.fromEntries(fields.map(entry => {
|
|
407
|
+
const { field: { fieldType, fieldID, name, requiredness }, } = entry;
|
|
408
|
+
if (!entry.type) {
|
|
409
|
+
entry.type = getGraphQLFunctionType(fieldType, fieldID?.value);
|
|
410
|
+
}
|
|
411
|
+
const { [typeKind]: type } = entry.type;
|
|
412
|
+
return [
|
|
413
|
+
name.value,
|
|
414
|
+
{
|
|
415
|
+
type: requiredness === 'required' ? new graphql_1.GraphQLNonNull(type) : type,
|
|
416
|
+
description,
|
|
417
|
+
},
|
|
418
|
+
];
|
|
419
|
+
}));
|
|
420
|
+
// We use fields thunk to avoid circular dependency in case of recursive types
|
|
424
421
|
outputTypeMap.set(typeName, new graphql_1.GraphQLObjectType({
|
|
425
422
|
name: typeName,
|
|
426
423
|
description,
|
|
427
|
-
fields:
|
|
424
|
+
fields: () => getFieldsMap('outputType'),
|
|
428
425
|
}));
|
|
429
426
|
inputTypeMap.set(typeName, new graphql_1.GraphQLInputObjectType({
|
|
430
427
|
name: typeName + 'Input',
|
|
431
428
|
description,
|
|
432
|
-
fields:
|
|
429
|
+
fields: () => getFieldsMap('inputType'),
|
|
433
430
|
}));
|
|
434
431
|
break;
|
|
435
432
|
}
|
package/esm/index.js
CHANGED
|
@@ -387,8 +387,6 @@ export default class ThriftHandler {
|
|
|
387
387
|
break;
|
|
388
388
|
case SyntaxType.StructDefinition: {
|
|
389
389
|
const description = processComments(statement.comments);
|
|
390
|
-
const objectFields = {};
|
|
391
|
-
const inputObjectFields = {};
|
|
392
390
|
const structTypeVal = {
|
|
393
391
|
id: Math.random(),
|
|
394
392
|
name: typeName,
|
|
@@ -397,37 +395,36 @@ export default class ThriftHandler {
|
|
|
397
395
|
};
|
|
398
396
|
topTypeMap[typeName] = structTypeVal;
|
|
399
397
|
const structFieldTypeMap = structTypeVal.fields;
|
|
398
|
+
const fields = [];
|
|
400
399
|
for (const field of statement.fields) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const description = processComments(field.comments);
|
|
405
|
-
const processedFieldTypes = getGraphQLFunctionType(field.fieldType, field.fieldID?.value);
|
|
406
|
-
fieldOutputType = processedFieldTypes.outputType;
|
|
407
|
-
fieldInputType = processedFieldTypes.inputType;
|
|
408
|
-
if (field.requiredness === 'required') {
|
|
409
|
-
fieldOutputType = new GraphQLNonNull(fieldOutputType);
|
|
410
|
-
fieldInputType = new GraphQLNonNull(fieldInputType);
|
|
411
|
-
}
|
|
412
|
-
objectFields[fieldName] = {
|
|
413
|
-
type: fieldOutputType,
|
|
414
|
-
description,
|
|
415
|
-
};
|
|
416
|
-
inputObjectFields[fieldName] = {
|
|
417
|
-
type: fieldInputType,
|
|
418
|
-
description,
|
|
419
|
-
};
|
|
420
|
-
structFieldTypeMap[fieldName] = processedFieldTypes.typeVal;
|
|
400
|
+
fields.push({ field, description: processComments(field.comments) });
|
|
401
|
+
const { typeVal } = getGraphQLFunctionType(field.fieldType, field.fieldID?.value);
|
|
402
|
+
structFieldTypeMap[field.name.value] = typeVal;
|
|
421
403
|
}
|
|
404
|
+
const getFieldsMap = (typeKind) => Object.fromEntries(fields.map(entry => {
|
|
405
|
+
const { field: { fieldType, fieldID, name, requiredness }, } = entry;
|
|
406
|
+
if (!entry.type) {
|
|
407
|
+
entry.type = getGraphQLFunctionType(fieldType, fieldID?.value);
|
|
408
|
+
}
|
|
409
|
+
const { [typeKind]: type } = entry.type;
|
|
410
|
+
return [
|
|
411
|
+
name.value,
|
|
412
|
+
{
|
|
413
|
+
type: requiredness === 'required' ? new GraphQLNonNull(type) : type,
|
|
414
|
+
description,
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
}));
|
|
418
|
+
// We use fields thunk to avoid circular dependency in case of recursive types
|
|
422
419
|
outputTypeMap.set(typeName, new GraphQLObjectType({
|
|
423
420
|
name: typeName,
|
|
424
421
|
description,
|
|
425
|
-
fields:
|
|
422
|
+
fields: () => getFieldsMap('outputType'),
|
|
426
423
|
}));
|
|
427
424
|
inputTypeMap.set(typeName, new GraphQLInputObjectType({
|
|
428
425
|
name: typeName + 'Input',
|
|
429
426
|
description,
|
|
430
|
-
fields:
|
|
427
|
+
fields: () => getFieldsMap('inputType'),
|
|
431
428
|
}));
|
|
432
429
|
break;
|
|
433
430
|
}
|