apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
574 stars 45 forks source link

query language for database's executable definitions #411

Open lrlna opened 1 year ago

lrlna commented 1 year ago

Would kind of be interesting to explore querying executable definition types with a smaller query language that we can use in the database.

Given a schema:

  interface Pet {
    name: String
  }

  type Dog implements Pet {
    name: String
    nickname: String
    barkVolume: Int
  }

  type Cat implements Pet {
    name: String
    nickname: String
    meowVolume: Int
  }

  union CatOrDog = Cat | Dog

  type Human {
    name: String
    pets: [Pet]
  }

  type Query {
    human: Human
  }

and a query like this:

{
  human {
    pets {
      name
    }
  }
}

it would be interesting to be able to do something like this compiler.db.query.find("human.pets.name").

goto-bus-stop commented 1 year ago

Would be interesting to see how we'd select a nickname field here as it can refer to two different definitions.

{
  human {
    pets {
       ... on Cat { nickname }
       ... on Dog { nickname }
    }
  }
}

Apollo federation internals in TypeScript has an OperationPath API to represent this and they heavily use it as well in query planning, we could have something similar.

I'm not sure a query language is the best way to frame it as I think in practice you'll almost always work with dynamic paths, so having a structured representation in memory is more important than writing a particular path by hand. Though we could always have a OperationPath::parse("human.pets.@Cat.nickname") for example.

goto-bus-stop commented 11 months ago

There is a spec proposal for operation paths: https://github.com/graphql/graphql-wg/blob/main/rfcs/OperationExpressions.md