1

I am trying to make my 1st Relay query. I did npm run relay and npm run build. Everything works well, but in console I am getting error: enter image description here

Does anybody know what may cause this error?

Update.

Table.js (component where I want make query)

import React, { Component } from 'react';
import { graphql, QueryRenderer } from 'react-relay';

const environment = import('../../environment.js');

class Table extends Component {

    render() {
        return (

        <QueryRenderer
            environment={environment}
            query={graphql`
                query TableQuery {
                    users {
                        data {
                            name
                        }
                    }
                  }
            `}
            render={({error, props}) => {
                return <div>User: 1</div>;
            }}
        />
        );
    }
}

export default Table;

environment.js (relay config)

import {
    Environment,
    Network,
    RecordSource,
    Store,
} from 'relay-runtime';

function fetchQuery(
    operation,
    variables,
) {
    return fetch('/graphql', {
        method: 'POST',
        headers: {
            'content-type': 'application/json'
        },
        body: JSON.stringify({
            query: operation.text,
            variables,
        }),
    }).then(response => {
        return response.json();
    });
}

const network = Network.create(fetchQuery);
const store = new Store(new RecordSource());

const environment = new Environment({
    network,
    store
});

export default environment;

Everything is from docs setup page.

2
  • Can you share the code which is causing this error? Nobody will be able to help you if all they can see is the errors in the console. Commented Mar 10, 2019 at 19:05
  • @Matt I made update. Commented Mar 10, 2019 at 19:14

1 Answer 1

1

In Table.js, it seems you mixed up the syntax for importing:

const environment = import('../../environment.js'); // Wrong

const environment = require('../../environment.js'); // OK
import environment from '../../environment.js'; // OK

Using import('../../environment.js') makes it a dynamic import which returns a Promise (depending on your bundler config) and is unlikely what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.