wilkerlucio / pathom3

Interface with complex data via graph mapping.
https://pathom3.wsscode.com
Eclipse Public License 2.0
376 stars 31 forks source link

Unable to re-use entrypoint data in a single request #151

Closed sheluchin closed 2 years ago

sheluchin commented 2 years ago

It looks like ::p.gql/root-entries-map entrypoints do not get re-used for all attributes in the request. My expectation is that if a request contains all of the attributes necessary for a GraphQL entrypoint, the entrypoint input requirements are satisfied.

In this example, there is a repository entrypoint. It can be used to pull data like :github.Repository/stargazerCount and :github.Repository/description. Requesting those attributes in separate requests produces the correct results, but if both attributes are combined into a single request, the latter one fails because it does not receive the entrypoint data.

I created a repro for this at: https://github.com/sheluchin/pathom3-graphql/commit/6f00a4d484ca0775963a945932ee5b780d256102. I'm not sure if this is specific to the GraphQL integration, but that's where I'm encountering them in my code, so I used the pathom3-graphql repo as the base.

For :github.Repository/stargazerCount:

{:com.wsscode.pathom3.connect.operation/op-name
 github/repository-ident-entry-resolver,
 :com.wsscode.pathom3.connect.planner/expects
 {:github.types/Repository {}},
 :com.wsscode.pathom3.connect.planner/input
 {:github.Repository/name {}, :github.User/login {}},
 :com.wsscode.pathom3.connect.planner/node-id 152,
 :com.wsscode.pathom3.connect.planner/node-parents #{190},
 :com.wsscode.pathom3.connect.planner/run-next 138,
 :com.wsscode.pathom3.connect.runner/node-done? true,
 :com.wsscode.pathom3.connect.runner/node-resolver-input
 {:github.Repository/name "pathom3",
  :github.User/login "wilkerlucio"},
 :com.wsscode.pathom3.connect.runner/node-resolver-output
 {:github.Repository/stargazerCount 256},

For :github.Repository/description:

    :com.wsscode.pathom3.connect.runner/node-resolver-input {}},
   :missing {:github.types/Repository {}},
   :required {:github.types/Repository {}}},
  :com.wsscode.pathom3.error/error-message
  "Insufficient data calling resolver 'github/pathom-entry-dynamic-resolver. Missing attrs :github.types/Repository",
wilkerlucio commented 2 years ago

Just pushed the commit https://github.com/wilkerlucio/pathom3-graphql/commit/69390399075cb2203f061ad037b134553efd1f40 on the GraphQL library that will output the correct results.

That said, I still see a problem in optimization. Currently, this code will call the GraphQL downstream twice, which is undesirable given it can be done in a single request. That goes down to Pathom planner optimizations, I'm currently figuring out how to safely optimize this scenario, so it makes a single request. This is the Graph I've been working on, using this query:

[{:repo-list
  [:github.Repository/stargazerCount 
   :github.Repository/description]}]
Screen Shot 2022-08-21 at 13 08 00

This should be merged.

wilkerlucio commented 2 years ago

Closing this for now, the other issue related to optimization, for now its working (also, not a bug in Pathom 3, but in Pathom 3 GraphQL, fixed over there)