comigor / artemis

Build dart types from GraphQL schemas and queries
MIT License
495 stars 119 forks source link

Automatically get current schema from api endpoint #81

Open LasseRosenow opened 4 years ago

LasseRosenow commented 4 years ago

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.

vasilich6107 commented 4 years ago

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

comigor commented 4 years ago

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).

vanelizarov commented 4 years ago

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!

comigor commented 4 years ago

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!

michael-golfi commented 3 years ago

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!

comigor commented 3 years ago

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

michael-golfi commented 3 years ago

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
johannbuscail commented 3 years ago

@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}"