我正在尝试将 graphql_flutter 用于我的颤振应用程序,但无法建立连接,并且出现以下错误:
I/flutter ( 6283): OperationException(linkException: ServerException(originalException: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 36582, parsedResponse: null), graphqlErrors: [])
我的猜测是错误说端口是 36582,但我的服务器在 localhost 的端口 4000 上。
这是主应用程序的代码
void main() async {
await initHiveForFlutter();
final HttpLink httpLink = HttpLink('http://localhost:4000/');
final AuthLink authLink = AuthLink(
getToken: () async => 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
// OR
// getToken: () => 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
);
final Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: link,
cache: GraphQLCache(
store: HiveStore(),
),
),
);
runApp(MyApp(client));
}
class MyApp extends StatelessWidget {
final ValueNotifier<GraphQLClient> client;
MyApp(this.client);
@override
Widget build(BuildContext context) {
return GraphQLProvider(
client: client,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
),
);
}
}
地址也是正确的,最后不包括“/graphql”。这些查询在邮递员和我的 Angular 应用程序的 apollo-client 中都可以正常工作。任何建议,将不胜感激。
这是给出错误的查询小部件
Query(
options: QueryOptions(
document: gql(ActionData.fetchCalendarActions),
variables: {
'userId': "60157b3dd6882132841d9a25",
'currentList': 'calendar'
}),
builder: (QueryResult result,
{VoidCallback refetch, FetchMore fetchMore}) {
if (result.hasException) {
print(result.exception.toString());
return Text(result.exception.toString());
}
if (result.isLoading) {
return Text('Loading');
}
print(result);
return Text('result');
},
),
这是查询:
class ActionData {
static String fetchCalendarActions =
"""query getCalendarActions(\$userId: ID!, \$currentList: String!) {
getActionForList(userId: \$userId, currentList: \$currentList ) {
_id
title
tags
}
}""";
}