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

Conditional resolving / optional expanding #1000

Open
demsr opened this issue Nov 10, 2022 · 0 comments
Open

Conditional resolving / optional expanding #1000

demsr opened this issue Nov 10, 2022 · 0 comments

Comments

@demsr
Copy link

demsr commented Nov 10, 2022

It would be nice if you could somehow make resolving conditional whether i request subfieds at all:

ExampleData:

vehicleData = [
  {
    licenseplate: "AB-CD123",
    customerNo: "1234"
  },
...
]

customerData = [
  {
    CusteormNo: "1234",
    Name: "John Doe"
  }
]

How it is

schemas:

type vehicle {
  licenseplate: String
  CustomerNo: String
  Customer: Customer
}

type Customer {
  CustomerNo: String
  Name: String
}

Resolver: 

 Vehicle: {
    Customer: ({ CustomerNo }, args, context, info) => {
     return customers.find( x => x.CustomerNo == CustomerNo )
    },
  },
query for vehicle without customer:

query ExampleQuery {
  vehicles{
    licenseplate
    CustomerNo
  }
}

query for vehicle with customer:

query ExampleQuery {
  vehicles{
    licenseplate
    Customer {
      CustomerNo
      Name
    }
  }
}

How i wish it would be

schemas:

type vehicle {
  licenseplate: String
  Customer: String | Customer  <- dynamic fields? 
}

type Customer {
  CustomerNo: String
  Name: String
}

Resolver: 

Vehicle: {
  Customer: ({ Customer }, args, context, info) => {
  if( _noSubfields_ ) return Customer; /* no expensive resolving */
   return customers.find( x => x.Customer== Customer)
  },
},
query for vehicle without customer:

query ExampleQuery {
  vehicles{
    licenseplate
    Customer 
  }
}

query for vehicle with customer:

query ExampleQuery {
  vehicles{
    licenseplate
    Customer {
      CustomerNo
      Name
    }
  }
}

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