我必须尝试使用graphql查询+中继从PostgreSQL数据库中获取所有数据。
我在以下文件中实现了一个查询:
const PropertyP = nextQuery<propertyQuery, { propertyId: string }>(ctx => ({
query: graphql`
query propertyQuery($propertyId: ID!) {
property: node(id: $propertyId) {
...Property_property
}
}
`,
variables: {
propertyId: ctx.query.propertyId || NULL_PROPERTY_ID,
},
// cacheStrategy: 'cache-first',
}))(PropertyPage);
和一个中继graphql文件,此文件位于
web/pages/__generated__/propertyQuery.graphql.js
此文件的内容如下:
const node/*: ConcreteRequest*/ = (function(){
var v0 = [
{
"kind": "LocalArgument",
"name": "propertyId",
"type": "ID!",
"defaultValue": null
}
],
v1 = [
{
"kind": "Variable",
"name": "id",
"variableName": "propertyId",
"type": "ID!"
}
];
return {
"kind": "Request",
"operationKind": "query",
"name": "propertyQuery",
"id": null,
"text": "query propertyQuery(\n $propertyId: ID!\n) {\n property: node(id: $propertyId) {\n __typename\n ...Property_property\n id\n }\n}\n\nfragment Property_property on Property {\n id\n livingSurface\n landSurface\n numberOfRooms\n numberOfParkings\n}\n",
"metadata": {},
"fragment": {
"kind": "Fragment",
"name": "propertyQuery",
"type": "Query",
"metadata": null,
"argumentDefinitions": v0,
"selections": [
{
"kind": "LinkedField",
"alias": "property",
"name": "node",
"storageKey": null,
"args": v1,
"concreteType": null,
"plural": false,
"selections": [
{
"kind": "FragmentSpread",
"name": "Property_property",
"args": null
}
]
}
]
},
"operation": {
"kind": "Operation",
"name": "propertyQuery",
"argumentDefinitions": v0,
"selections": [
{
"kind": "LinkedField",
"alias": "property",
"name": "node",
"storageKey": null,
"args": v1,
"concreteType": null,
"plural": false,
}
]
}
};
})();
// prettier-ignore
(node/*: any*/).hash = '568e84b911100cf5010ec35e0b6ff480';
module.exports = node;
此文件保留继电器和graphql中的查询和操作。
我尝试从属性表中的特定propertyId
获取所有数据。但是,它仅返回属性id。
所以,如何获取React.Component
文件中的所有数据