Apollo Graphql mocking fragment data

Viewed 491

I have managed to use Apollo's data mocking for queries. This is what I have so far:

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])
})

This works... but it is not ideal as what I really want is the fragment data, I don't care about the query at all. Is there any way of doing this with just MyFragment without having to create a query to retrieve that data?

0 Answers
Related