graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Make request with no schema

Open CodyZeusLiving opened this issue 6 years ago • 6 comments

I am trying to make a request from an endpoint for which I do not have the schema available. Additionally, the endpoint is configured not to respond to introspection requests. Whenever I try to initialize a client with a nil schema, I get an error:

gems/ruby-2.5.1/gems/graphql-1.9.6/lib/graphql/schema/loader.rb:16:in `fetch': key not found: "data" (KeyError)

I know the fields I want to request; is there a way to make the request without having to specify a schema?

CodyZeusLiving avatar Jun 25 '19 00:06 CodyZeusLiving

There are several parts of this client that rely on the schema being present. Once the client is initialized, you must then register the queries with the client before you're allowed to use them. The registration process validates the query against the schema and disallows the query if it doesn't match.

If you don't have the schema available with a local file, and the API doesn't respond to introspection, you probably can't use this client. You can always serialize the requests as normal HTTP Posts - the only major difference is you won't get the nice serialization that this client provides (e.g. response.data.my_query.my_data is much nicer than response.body['data']['myQuery']['myData'] - but the latter is a good fallback if you need to get around the schema requirements)

ericyd avatar Aug 01 '19 16:08 ericyd

Yeah.. but seems like this client is also based on https://github.com/rmosolgo/graphql-ruby which 'just' released their 'disable_introspective_query_in_production' thing... (which is the root of the reported error) -> https://github.com/rmosolgo/graphql-ruby/pull/2327...

leoGalani avatar Aug 15 '19 08:08 leoGalani

Any update to this issue? The production server cannot be run with introspection turned on.

hwasoocho avatar Jan 07 '20 09:01 hwasoocho

I just ran into the same issue. We are using Apollo Gateway and have introspection queries disabled in production.

As @leoGalani said since this client so closely related to graphql-ruby it makes sense to be able to handle this feature in the client as well.

I don't like the idea of removing this gem in my application and doing the requests without an abstraction layer. The local file also doesn't sound appealing as its a workaround creating maintenance overhead.

My question at this point is if you consider changing the client into that direction or if its out of scope?

robinboening avatar Sep 30 '20 20:09 robinboening

In my opinion it's an overkill to use graphql-client if you cannot fetch the schema, except you are using graphql-client for other hosts which do have an schema. Otherwise you can just use/extract a simple HTTP client like the one in graphql/client/http.rb and build the requests yourself in an easy manner.

Regarding the nice serialization of the response, you can simply use HashDot or Hashie or any other similar gem.

pjmartorell avatar Apr 19 '21 02:04 pjmartorell

You can run dump_schema and store it in a shared bucket.

chmoreira-blu avatar Oct 12 '21 22:10 chmoreira-blu