我对graph-ql不太了解,需要可以运行的演示设置。 我被困住了,不知道如何设置客户端, 谁能解释一下如何在此给定代码中设置客户端:-
https://github.com/zino-app/graphql-flutter/blob/master/example/lib/main.dart
Client(
endPoint: 'https://api.github.com/graphql',
cache: InMemoryCache(),
apiToken: '<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN>',
),
还有什么是ReadRepositories
String readRepositories = """
query ReadRepositories {
viewer {
repositories(last: 50) {
nodes {
id
name
viewerHasStarred
}
}
}
}
"""
.replaceAll('\n', ' ');
答案 0 :(得分:0)
static HttpLink httpLink = HttpLink(
uri: 'https://api.github.com/graphql',
);
final AuthLink authLink = AuthLink(
getToken: () async => 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
);
final Link link = authLink.concat(httpLink as Link);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: link,
),
);
- For Call query user Query method for GraphQlProvider.
Query(
options: QueryOptions(
document: readRepositories, pollInterval: 1),
builder: (QueryResult result, {VoidCallback refetch}) {
if (result.loading) {
return Center(child: CircularProgressIndicator());
}
if (result.errors != null) {
return Text(result.errors.toString());
}
if (result.data == null) {
return Center(child: Text("No Data Found !"));
}
// After getting response, return your result
return YourWidget();
},
),
);