Hof*_*ann 6 apollo graphql apollo-client
我已经设法使用 Apollo 的数据模拟进行查询。这是我到目前为止:
import { addMocksToSchema } from '@graphql-tools/mock'
import { buildClientSchema, graphql } from 'graphql'
import schemaJson from './schema.json'
const schema = buildClientSchema(schemaJson)
const schemaWithMocks = addMocksToSchema({
schema,
mocks: {
Time: () => '2020-07-10T11:00:00.839379266Z',
},
})
const MyFragment = `
fragment MyFragment on SomethingItemList {
someField
}
`
graphql({
schema: schemaWithMocks,
source: `
${MyFragment}
query FaultInfoStoryBatterySystems {
something {
item {
list {
...MyFragment
}
}
}
}
`
}).then((mockedData) => {
console.log('Fragment Data:', mockedData.something.item.list[0])
})
Run Code Online (Sandbox Code Playgroud)
这有效......但它并不理想,因为我真正想要的是片段数据,我根本不关心查询。有没有什么办法可以只用 MyFragment 做到这一点,而不必创建查询来检索该数据?
| 归档时间: |
|
| 查看次数: |
238 次 |
| 最近记录: |