[英]apollo-link-rest: query with dynamic fields in response
I'm requesting a Salesforce schema data.我正在请求 Salesforce 模式数据。 It has a format
它有一个格式
res = {
Id: { name, type, label },
IsDeleted: { type, name, label },
MasterRecordId: { type, name, label },
...and so on
}
So, fields are dynamic.因此,字段是动态的。 In queries.js I'm trying to describe it
在 query.js 我试图描述它
export const GET_SALESFORCE_FIELDS = gql`
query SalesforceFields {
salesforceFields @rest(endpoint: "schemaservice", type: "SalesforceFields", path: "/fields") {
// What should be here??
}
}
`;
`
How can I describe the dynamic part?如何描述动态部分? I don't have any schema files or resolvers.
我没有任何架构文件或解析器。 Only queries.js (for further requests with useQuery) and client.js (where the
new ApolloClient
is defined)只有 queries.js(用于使用 useQuery 的进一步请求)和 client.js(定义了
new ApolloClient
)
"@apollo/client": "^3.0.0-rc.10",
"apollo-link-rest": "^0.8.0-beta.0"
Solved in this way:以这种方式解决:
// queries.js
export const GET_SALESFORCE_FIELDS = gql`
query SalesforceFields {
salesforceFields @rest(endpoint: "schemaservice", type: "SalesforceFieldsPayload", path: "/fields") {
items @type(name: "Salesforce")
}
}
`;
// client.js
const restLink = new RestLink({
...,
typePatcher: {
SalesforceFieldsPayload: (
data,
outerType,
patchDeeper
) => {
if (data != null) {
data.items = Object.keys(data).map(field => ({ __typename: "Salesforce", ...data[field] }));
}
return data;
}
}
});
A reference to GitHub: https://github.com/apollographql/apollo-link-rest/issues/258参考 GitHub: https://github.com/apollographql/apollo-link-rest/issues/258
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.