Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In getDefaultScalarArgValue, unable to determine parent argument for sub-arguments of object arguments #40

Open
baohouse opened this issue Jan 14, 2020 · 0 comments

Comments

@baohouse
Copy link

So in my use case I have the following schema (simplified to the relevant bits):

type Mutation {
  signUp(company: CompanyInput, family: FamilyInput): SignupResult
}
type CompanyInput {
  type: OrganizationType
}
type FamilyInput {
  type: OrganizationType
}
enum OrganizationType {
  COMPANY
  FAMILY
}

So my goal is to auto-populate the organizationType based on whether it belongs within CompanyInput or FamilyInput. So that's where getDefaultScalarArgValue comes in.

getDefaultScalarArgValue(parentField, arg, argType) {
  /* LOGIC GOES HERE */
}

However, as it executes, when I select the organizationType within CompanyInput which invokes getDefaultScalarArgValue, parentField shows as signUp, arg is organizationType, and argType is OrganizationType. The problem is that you don't know who the immediate parent arg type is (which should be CompanyInput).

My thought is that within this part of AbstractArgView class, we need to pass in a parentArg prop.

if (argValue.kind === 'ObjectValue') {
const fields = argType.getFields();
input = (
<div style={{marginLeft: 16}}>
{Object.keys(fields)
.sort()
.map(fieldName => (
<InputArgView
key={fieldName}
arg={fields[fieldName]}
parentField={this.props.parentField}
selection={argValue}
modifyFields={this.props.setArgFields}
getDefaultScalarArgValue={
this.props.getDefaultScalarArgValue
}
makeDefaultArg={this.props.makeDefaultArg}
onRunOperation={this.props.onRunOperation}
styleConfig={this.props.styleConfig}
/>
))}
</div>
);

And this propagate that to getDefaultScalarArgValue, which would change its signature however:

getDefaultScalarArgValue(parentField, arg, argType, parentArg) {
  /* LOGIC GOES HERE */
}

I'm wary of making signature changes. But when I pass in the parentArg, I can see that the organizationType belongs to CompanyInput or FamilyInput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant