“Evaluation of custom field failed because external request returned an error: unexpected status code: 502 for field: MyMutation within type: Mutation.”
I have tested my script with Insomnia and can get a response in the form of MyResponse above by doing a post request with a JSON body and a Content-Type:application/json header.
I assume that Dgraph makes the request taking my body and POSTing it with the application/json header. I am not sur ewhat else I am missing from here.
This would help bring our authentication script into the same domain with our API.
Running v2.0.0-rc1-518-g3c710183a which was the latest master branch from 7/15 I believe
No, that header is not set by dgraph. I think we should add it because we only support JSON payloads in custom HTTP requests anyways.
But, just to check, Can you once try the request from Insomnia/Postman without the Content-type header, and see if it works. If that fails, you may need to modify your schema like this for now:
And then send a mutation request to Dgraph with X-forward-Content header set to "application/json". And it would be forwarded to your script as Content-type header.
I can’t figure out how this could be related to 502 though. Are there any network limitations on the machine you are running dgraph? Also, are you running Insomnia on the same machine as dgraph? If not, can you try that?
yeah, without that header from my local machine I get 502 Bad Gateway.
I cannot run insomnia on my dgraph machine because it is actually a docker machine running in an ec2 instance on AWS. I can probably get around this by the time being by doing the additional headers with the original request and forwarding headers.
Feature Request: Can we add a headers parameter in the custom directive so that we can send custom headers without them needing to be set by the original request.
Overview: 1) Client makes standard graphql request with no special headers. 2) Dgraph receives the request, maps it to the custom mutation/query/field. 3) Dgraph adds headers and sends it to the url.
It was initially designed to store secrets in the schema. But, it could be used here as well . This should work for you until we don’t send this header automatically.
This was the solution that was needed! My custom mutation now works and I can use my Authentication script from within my graphql endpoint! Thanks @abhimanyusinghgaur