You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fields with Arguments Incorrectly Generated as Primitive Properties
Bug Description
The generator incorrectly treats GraphQL fields that have arguments as primitive properties in the MST model, when they should be handled as computed fields or methods.
Expected Behavior
Fields with arguments should:
Not be added to the MST model .props()
Not generate getter-style selectors
Generate method-style selectors that accept arguments
Actual Behavior
Fields with arguments are:
Added to MST model props as stored properties
Generate getter-style selectors that ignore the arguments
Added to primitiveFields and included in modelPrimitives
exportconstOfferBundleAggregationModelBase=ModelBase.named('OfferBundleAggregation').props({__typename: types.optional(types.literal("OfferBundleAggregation"),"OfferBundleAggregation"),// ❌ These should NOT be properties since they have argumentshashRate24Hr: types.union(types.undefined,types.null,types.number),hashRateIdeal: types.union(types.undefined,types.null,types.number),powerUsage24Hr: types.union(types.undefined,types.null,types.number),powerManufacturer: types.union(types.undefined,types.null,types.number),// ... other props})exportclassOfferBundleAggregationModelSelectorextendsQueryBuilder{// ❌ These should NOT be getters since they require argumentsgethashRate24Hr(){returnthis.__attr(`hashRate24Hr`)}gethashRateIdeal(){returnthis.__attr(`hashRateIdeal`)}getpowerUsage24Hr(){returnthis.__attr(`powerUsage24Hr`)}getpowerManufacturer(){returnthis.__attr(`powerManufacturer`)}// ... other methods}
Expected Generated Output
exportconstOfferBundleAggregationModelBase=ModelBase.named('OfferBundleAggregation').props({__typename: types.optional(types.literal("OfferBundleAggregation"),"OfferBundleAggregation"),// ✅ Only fields without arguments should be properties// hashRate24Hr, hashRateIdeal, etc. should NOT be here})exportclassOfferBundleAggregationModelSelectorextendsQueryBuilder{// ✅ Fields with arguments should be methodshashRate24Hr(args: {unit: HashRateUnit}){returnthis.__attr(`hashRate24Hr`,args)}hashRateIdeal(args: {unit: HashRateUnit}){returnthis.__attr(`hashRateIdeal`,args)}powerUsage24Hr(args: {unit: PowerUnit}){returnthis.__attr(`powerUsage24Hr`,args)}powerManufacturer(args: {unit: PowerUnit}){returnthis.__attr(`powerManufacturer`,args)}// ... other methods}
Root Cause
In the handleFieldType() function around line 449, when processing SCALAR fields, the code adds ALL scalar fields to primitiveFields regardless of whether they have arguments:
case"SCALAR":
primitiveFields.push(fieldName)// ❌ This happens even for fields with args// ...
Proposed Fix
The logic should check for arguments before classifying fields:
case"SCALAR":
if(fieldArgs&&fieldArgs.length>0){// Fields with arguments should be treated as methods, not stored propertiesnonPrimitiveFields.push([fieldName,fieldType.name,fieldArgs])}else{// Only fields without arguments should be primitivesprimitiveFields.push(fieldName)}// ... rest of scalar handling
Environment
mst-gql version: ^0.17.2
Node version: v18.17.0
Additional Context
This affects any GraphQL schema that uses scalar fields with arguments for computed values, which is a common pattern for fields that need unit conversions, formatting options, or other parameterized transformations.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Fields with Arguments Incorrectly Generated as Primitive Properties
Bug Description
The generator incorrectly treats GraphQL fields that have arguments as primitive properties in the MST model, when they should be handled as computed fields or methods.
Expected Behavior
Fields with arguments should:
.props()
Actual Behavior
Fields with arguments are:
primitiveFields
and included inmodelPrimitives
Example
GraphQL Schema
Current Generated Output (Incorrect)
Expected Generated Output
Root Cause
In the
handleFieldType()
function around line 449, when processingSCALAR
fields, the code adds ALL scalar fields toprimitiveFields
regardless of whether they have arguments:Proposed Fix
The logic should check for arguments before classifying fields:
Environment
Additional Context
This affects any GraphQL schema that uses scalar fields with arguments for computed values, which is a common pattern for fields that need unit conversions, formatting options, or other parameterized transformations.
Beta Was this translation helpful? Give feedback.
All reactions