Как передать фрагменты в запросе graphql? ниже тестовый пример не работает. в reactjs клиент apollo graphql - PullRequest
1 голос
/ 01 мая 2020

Фрагмент в запросе graphql не работает. Я пытаюсь передать фрагмент, как показано ниже, в постоянном запросе, этот запрос успешно выполняется на сервере graphql. Я не знаю, где я ошибаюсь. Это правильный способ передачи фрагмента или нет. Пожалуйста, проверьте код ниже и предоставьте мне свое предложение, чтобы решить эту проблему, и успешно запустите этот тестовый пример

    import React from 'react';
    import gql from 'graphql-tag';
    import { MockedProvider } from '@apollo/client/testing';
    import { render, wait } from '../../../test-utils';

    describe('customer list', () => {
    it('render with data', async () => {  

            const query = gql`
            fragment Customer on Customer {
            id
            userId
            firstName
            lastName
            status
            dateOfBirth
            }
            query getCustomers {
            customers {
                ...Customer
            }
            }
        `;


        const mocks = [
        {
            request: {
            query
            },
            result: {
            data: {
                customers: [
                {
                    id: 'tid1',
                    userId: 'test1',
                    firstName: 'test f',
                    lastName: 'test l',
                    status: 'testactive',
                    contactInfo: {
                    email: 'test@gmail.com',
                    phone: '797789956',
                    address: {
                        unit: '123',
                        streetAddress: 'test',
                        city: 'mp',
                        jurisdictionCode: 'tst',
                        country: 'xyz',
                        postalCode: '412356'
                    }
                    },
                    dateOfBirth: '12/12/2014'
                },
                {
                    id: 'tid2',
                    userId: 'test2',
                    firstName: 'test2 f',
                    lastName: 'test2 l',
                    status: 'active',
                    contactInfo: {
                    email: 'test@gmail.com',
                    phone: '797789956',
                    address: {
                        unit: '123',
                        streetAddress: 'test',
                        city: 'mp',
                        jurisdictionCode: 'sds',
                        country: 'yxz',
                        postalCode: '412356'
                    }
                    },
                    dateOfBirth: '12/12/2014'
                },
                {
                    id: 'tid3',
                    userId: 'test3',
                    firstName: 'test3 f',
                    lastName: 'test3 l',
                    status: 'active',
                    contactInfo: {
                    email: 'test1@gmail.com',
                    phone: '797789956',
                    address: {
                        unit: '123',
                        streetAddress: 'test',
                        city: 'mp',
                        jurisdictionCode: 'sds',
                        country: 'zxy',
                        postalCode: '412356'
                    }
                    },
                    dateOfBirth: '12/12/1995'
                }
                ]
            }
            }
        }
        ];

        const { asFragment, findByText } = render(
        <MockedProvider mocks={mocks} addTypename={false}>
            <Customers />
        </MockedProvider>
        );
        const testid1 = await findByText('tid1');
        expect(testid1).toBeInTheDocument();

        const testfname = await findByText('test f');
        expect(testfname).toBeInTheDocument();

        const testlname = await findByText('test l');
        expect(testlname).toBeInTheDocument();

        const status = await findByText('testactive');
        expect(status).toBeInTheDocument();

        const email = await findByText('test1@gmail.com');
        expect(email).toBeInTheDocument();

        const DOB = await findByText('12/12/1995');
        expect(DOB).toBeInTheDocument();

        await wait(() => expect(asFragment()).toMatchSnapshot());
    });
    });

Если кто-то может помочь, необходимо оценить.

...