Skip to content

Dependency graph design #1566

Description

@andimarek

I want to capture here some thoughts about the Dependency graph (see #1409).

One of the main challenges is the dynamic aspects of a query (type conditions).

For exampel for this schema:

type Query{ 
    node: Node
}
interface Animal {
    name: String
    friends: [Friend]
}

union Pet = Dog | Cat

type Friend {
    name: String
    isBirdOwner: Bool
    isCatOwner: Bool
    pets: [Pet] 
}

type Bird implements Animal {
   name: String 
   friends: [Friend]
}

type Cat implements Animal{
   name: String 
   friends: [Friend]
   breed: CatBreed 
}

type Dog implements Animal{
   name: String 
   breed: DogBreed
   friends: [Friend]
}

scalar DogBreed
scalar CatBreed

one can imagine this query:

{
  node
  ... on Cat {
    friends {
      isCatOwner
      name
      pets {
        name
        ... on Cat {
          breed
        }
      }
    }
  }
  ... on Bird {
    name
    friends {
      isBirdOwner
      name
      pets {
        name
        ... on Dog {
          breed
        }
      }
    }
  }
  ... on Dog {
    name
  }
}

The question is now how the dependency graph should capture these dynamic type conditions.
One possible way could be this:
Screen Shot 2019-06-10 at 11 15 36 am

But the value of this kind of dependency graph maybe limited because it doesn't uphold to one fundamental expectation that every field is only present once.
The /node/friends/pets/name field is duplicated because it will only be executed if we have a Bird or a Cat, but not for a Dog.

Same is true for /node/friends/pets and /node/friends/name.

The alternative could maybe look like this:
Screen Shot 2019-06-10 at 11 34 45 am

It doesn't duplicate any fields anymore but now there are complex conditions associated with some nodes. For example /node/friends/pets/breed will only be evaluated if the original node is a Cat and the pet is a Dog.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions