question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dependency graph design

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
andimarekcommented, Jul 8, 2019

After giving it some more thought and actually implementing it/spiking it, I come up with a design where each node represents always a field of an object type. Fragments/type condition/field on interfaces are all resolved to fields on object types. At execution time only object types matter and which interfaces/union is implemented by which object is statically known by the schema definition.

I created also a small interactive page to play around/visualize this: https://www.graphql-analyzer.com/

A PR which adds this dependency graph to GraphQL Java will follow.

0reactions
andimarekcommented, Jul 11, 2019

closing this now … thanks a lot @gkesler @exbe for the valuable discussion!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Draw dependency graphs in diagrams.net
Puzzle dependency charts, narrative dependency diagrams and navigation graphs are used by game designers and writers to plan adventure and ...
Read more >
Dependency Graph in Compiler Design - GeeksforGeeks
A dependency graph is used to represent the flow of information among the attributes in a parse tree. In a parse tree, a...
Read more >
Without Seeing Your Application's Dependency Graph, You're ...
Dependency graphs do an excellent job of depicting how elements in your codebase depend on one another. You can use them for methods,...
Read more >
Dependency Graph - DeepSource
A dependency graph is a directed graph that describes the dependency of an entity in the system on the other entities of the...
Read more >
Dependency graph | Lucidchart
This dependency graph template can help you: - Visualize dependencies of different objects. - Collaborate with colleagues. Open this template to view a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found