要解决Apollo-GraphQL客户端拒绝Base64字符串数据的问题,您可以尝试使用以下解决方法:
使用apollo-link-rest插件:
import { RestLink } from 'apollo-link-rest';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
const restLink = new RestLink({
uri: 'https://api.example.com',
customFetch: async (uri, options) => {
if (options.body && options.body.variables && options.body.variables.file) {
options.body.variables.file = options.body.variables.file.toString('base64');
}
return fetch(uri, options);
},
});
const client = new ApolloClient({
link: restLink,
cache: new InMemoryCache(),
});
自定义Apollo-GraphQL链接:
import { ApolloLink } from 'apollo-link';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
const customLink = new ApolloLink((operation, forward) => {
if (operation.variables && operation.variables.file) {
operation.variables.file = operation.variables.file.toString('base64');
}
return forward(operation);
}).concat(new HttpLink({ uri: 'https://api.example.com' }));
const client = new ApolloClient({
link: customLink,
cache: new InMemoryCache(),
});
请注意,以上解决方法仅为示例,您可能需要根据您的具体情况进行调整。另外,请确保您的Base64字符串数据正确传递给Apollo-GraphQL客户端。