dart-graphql / graphql_client

GraphQL Client.
https://pub.dartlang.org/packages/graphql_client
MIT License
78 stars 9 forks source link

Use gql query as string instead of the internal dsl #2

Closed hourliert closed 7 years ago

hourliert commented 7 years ago

Fixes #1 .

Caveats:

Sample of code:

  final client = new Client();
  final logger = new Logger('GraphQLClient');
  final graphQLClient = new GraphQLClient(
    client: client,
    logger: logger,
    endPoint: endPoint,
  )..loadSchema(GithubGraphQLSchema);

  //language=GraphQL
  String gqlQuery = '''
    query {
      viewer {
        avatarUrl(size: 200)
        login
        bio @include(if: false)
        gists(first: 5) {
          nodes {
            ...ShortGist
          }
        }
      }
    }

    fragment ShortGist on Gist {
      name
      description
    }
  ''';

  var res = await graphQLClient.execute<GithubGraphQLSchema>(
    gqlQuery,
    headers: {'Authorization': 'bearer $apiToken'},
  );

  print(res.viewer.avatarUrl.value);
  print(res.viewer.gists.nodes.first.name.value);