I am interested in generating contracts where Grap...
# pact-js
d
I am interested in generating contracts where GraphQL DataSources are consumers of other API providers. Are there any recommended patterns to follow? The existing documentation for GraphQL interactions appears to demonstrate how to generate contracts for consumers of GraphQL providers.
m
It should look like any standard Pact test really. Unless I’m missing something about how they make API calls?
t
The graphql idiom seems to be not to separate out your downstream API from what would be the “controller” in a rest api
But yes - Matt’s answer is what I would say. Your Pact test should be around the downstream API client, not the GraphQL datasource
as in, it shouldn’t matter whether your provider is itself graphql or anything else
You might find some of the advice around passthrough APIs applies to your case, maybe
d
I am running into trouble with the
RESTDataSource
implementation with Apollo. It seems that it is dependent on the
ApolloServer
, so I cannot instantiate a working client outside of the server. I could instantiate an
ApolloServer
with the datasource configured to hit the
PactV3
provider, however I would need a way to differentiate the provider ID based on the data source. Is it possible to set up a
PactV3
provider that builds separate pacts based on the path being hit?
For example, instead of specifying a single provider in the initialization, could i do something like
Copy code
providers: {
  '/base/path/one': 'provider1',
  '/base/path/two': 'provider2',
   . . .
  '/base/path/n': 'providerN'
}
m
I don't think so, but you could post process the pact file and split it out the interactions as needed
👍🏻 1