artemis icon indicating copy to clipboard operation
artemis copied to clipboard

Automatically get current schema from api endpoint

Open LasseRosenow opened this issue 6 years ago • 8 comments

If you use the javascript graphql "Apollo", then you don't have do put any schema.json or schema.graphql in your project at all. Apollo automatically gets the current schema just by the url you specify like this:

schema: https://example.myapi.com/gql/graphql

I think it would be cool to have this in artemis as well.

LasseRosenow avatar Feb 09 '20 23:02 LasseRosenow

Hi. Referring to this article https://medium.com/@v.ditsyak/ultimate-toolchain-to-work-with-graphql-in-flutter-13aef79c6484 - having the schema locally will benefit in code completion in your graphql files

vasilich6107 avatar Feb 14 '20 20:02 vasilich6107

Hey @lazylazyllama!

Yeah, that sure would be nice (and we can think of a way of saving it to disk and still benefit from code completion).

My only concern with this is mostly API's would required an authentication mechanism (something easy as header tokens, but most times certs that would require a custom http client).

comigor avatar Feb 14 '20 20:02 comigor

Hey @comigor!

Cool that you've added tool/fetch_schema.dart, now it's not necessary to fetch schema with npm packages or other non-dart ways 🙂

It would be also cool to have this util in bin folder as described here to be able to run it through

pub run artemis:fetch_schema

or

flutter pub run artemis:fetch_schema

Thanks!

vanelizarov avatar Feb 20 '20 11:02 vanelizarov

Hey @vanelizarov,

That's of course a quick way of doing it, but it doesn't solve the authentication problem I've mentioned before.

Also, we're working on adding SDL support for schemas (https://github.com/comigor/artemis/pull/82) and then we'd need to change this. But feel free to open a PR if you'd like to use this tool right now!

comigor avatar Feb 21 '20 13:02 comigor

Hey @comigor,

Just checking in, is it possible to fetch a schema directly from an endpoint? Our API isn't gated by an authentication header for introspection.

Thanks in advance!

michael-golfi avatar Mar 01 '21 20:03 michael-golfi

I previously used this tool, but I'm not if it still works.

comigor avatar Mar 01 '21 20:03 comigor

Do you have any plans to support this in the library so that a schema can be specified as an endpoint?

targets:
  $default:
    builders:
      artemis:
        options:
          schema_mapping:
            - output: lib/graphql_api.dart
              schema: https://{some endpoint}/graphql
              queries_glob: lib/**.graphql

michael-golfi avatar Mar 01 '21 21:03 michael-golfi

@comigor Any update on this ? Coming from React Native, codegen allowed that really easily just by setting the endpoint in the codegen.yml file. For the authentication problem, according to https://github.com/dotansimha/graphql-code-generator/issues/2029 here's what was needed with codegen:

schema:
  - http://localhost:3000/graphql:
      headers:
        Authorization: "Bearer: ${API_TOKEN}"

johannbuscail avatar Jul 07 '21 12:07 johannbuscail