Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to mock Apollo GQL requests? #11

Open
ThingCoDanW opened this issue Oct 30, 2020 · 2 comments
Open

Is it possible to mock Apollo GQL requests? #11

ThingCoDanW opened this issue Oct 30, 2020 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@ThingCoDanW
Copy link

It looks like Mockiavelli is not catching these at all - I get no errors or warnings about unhandled API calls, and when I do try to handle them they are hitting the endpoint and failing as I've mocked out the Auth part of my app. Is there some additional config I need to make this work, or is it simply not possible?

@lukaszfiszer
Copy link
Member

There is no dedicated support for GraphQL - we dont dont use it in HL Tech, and nobody had requested such a feature (yet).

However, I think you should be able to mock all your graphql requests with .mockPOST on your graphQl endpoint. Can you run Mockiavelli with debug mode and see what is being logged?

@lukaszfiszer lukaszfiszer added enhancement New feature or request question Further information is requested labels Oct 31, 2020
@ThingCoDanW
Copy link
Author

ThingCoDanW commented Nov 2, 2020

mockiavelli:main Initialized +0ms
  mockiavelli:mock + (1) created mock: method=POST url=https://firebaseinstallations.googleapis.com/v1/projects/<FIREBASE_ID>/installations  +0ms
  mockiavelli:main > req: type=document method=GET url=http://localhost:3000/  +36ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +30ms
  mockiavelli:main < res: continue +1ms
  mockiavelli:main > req: type=stylesheet method=GET url=https://api.tiles.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.css  +1s
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +1s
  mockiavelli:main < res: continue +1ms
  mockiavelli:main > req: type=script method=GET url=http://localhost:3000/bundle.js  +1ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +1ms
  mockiavelli:main < res: continue +1ms
  mockiavelli:main > req: type=script method=GET url=https://www.googletagmanager.com/gtag/js?l=dataLayer  +596ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +598ms
  mockiavelli:main < res: continue +2ms
  mockiavelli:main > req: type=fetch method=POST url=https://firebaseinstallations.googleapis.com/v1/projects/<FIREBASE_ID>/installations  +4ms
  mockiavelli:mock = (1) matched mock  +6ms
  mockiavelli:main < res: status=200 headers={"content-length":"0","Access-Control-Allow-Origin":"http://localhost:3000","Access-Control-Allow-Credentials":"true"} body= +3ms
  mockiavelli:main > req: type=font method=GET url=http://localhost:3000/fonts/poppins-regular.woff2  +37ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +40ms
  mockiavelli:main < res: continue +1ms
  mockiavelli:mock + (2) created mock: method=POST url=https://<COGNITO>.amazonaws.com/  +102ms
  mockiavelli:main > req: type=script method=GET url=http://www.googletagmanager.com/gtag/js?id=<GTAG>&l=dataLayer&cx=c  +107ms
  mockiavelli:mock · (2) method not matched: mock=POST req=GET   +5ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +1ms
  mockiavelli:main < res: continue +1ms
  mockiavelli:main > req: type=other method=POST url=https://www.google-analytics.com/g/collect?v=2&tid=<GTAG>&gtm=2oeal2&_p=1578975262&sr=1280x720&ul=en-gb&_fid=<ID>&cid=<ID>&_s=1&dl=http%3A%2F%2Flocalhost%2F&dr=&dt=<APPNAME>&sid=<ID>&sct=1&seg=0&en=page_view&_fv=1&_nsi=1&_ss=1&ep.origin=firebase  +78ms
  mockiavelli:mock · (2) url not matched: mock=https://<COGNITO>.amazonaws.com req=https://www.google-analytics.com   +78ms
  mockiavelli:mock · (1) url not matched: mock=https://firebaseinstallations.googleapis.com req=https://www.google-analytics.com   +1ms
  mockiavelli:main < res: continue +1ms
  mockiavelli:main > req: type=fetch method=POST url=https://<COGNITO>.amazonaws.com/  +16ms
  mockiavelli:mock = (2) matched mock  +16ms
  mockiavelli:main < res: status=200 headers={"content-length":"109","content-type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"http://localhost:3000","Access-Control-Allow-Credentials":"true"} body={"ChallengeName":"CUSTOM_CHALLENGE","ChallengeParameters":{"USERNAME":"123","email":"test"},"Session":"test"} +2ms
  mockiavelli:main > req: type=fetch method=POST url=https://<COGNITO>.amazonaws.com/  +165ms
  mockiavelli:mock = (2) matched mock  +168ms
  mockiavelli:main < res: status=200 headers={"content-length":"109","content-type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"http://localhost:3000","Access-Control-Allow-Credentials":"true"} body={"ChallengeName":"CUSTOM_CHALLENGE","ChallengeParameters":{"USERNAME":"123","email":"test"},"Session":"test"} +6ms
  mockiavelli:mock + (3) created mock: method=POST url=https://<APPSYNC_URL>.amazonaws.com/graphql  +85ms
  mockiavelli:main > req: type=font method=GET url=http://localhost:3000/fonts/poppins-bold.woff2  +553ms
  mockiavelli:mock · (3) method not matched: mock=POST req=GET   +474ms
  mockiavelli:mock · (2) method not matched: mock=POST req=GET   +0ms
  mockiavelli:mock · (1) method not matched: mock=POST req=GET   +0ms
  mockiavelli:main < res: continue +2ms

You can see the sucessful mocks for Cognito and Firebase analytics, and the creation of the Appsync mock, but the mock itself is not matched and this is where the script hangs as it cannot continue with the stubbed Auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants