OneGraph / graphiql-explorer

Explorer plugin for GraphiQL
MIT License
904 stars 97 forks source link

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

Open baohouse opened 4 years ago

baohouse commented 4 years ago

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. https://github.com/OneGraph/graphiql-explorer/blob/69da97c4a3de988a405caa2707ec9a4133e4b614/src/Explorer.js#L790-L812

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.