这是我第一次使用 Ferry 发出 GraphQL 请求。我的 GraphQL Server 有一些查询需要 HTTP 标头进行授权。
我需要能够在初始化客户端后添加标头。
客户端.dart:
Future<Client> initClient() async {
await Hive.initFlutter();
final box = await Hive.openBox<Map<String, dynamic>>("graphql");
await box.clear();
final store = HiveStore(box);
final cache = Cache(store: store);
final link = HttpLink("example.com/");
final client = Client(
link: link,
cache: cache,
);
return client;
}
Run Code Online (Sandbox Code Playgroud)
主.dart:
void main() async{
final client = await initClient();
GetIt.I.registerLazySingleton<Client>(() => client);
runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)
请求文件:
client.request(Req).listen((response) {
print(response.graphqlErrors); // It will return an error because theres …Run Code Online (Sandbox Code Playgroud)