Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing preloadedRequests to prepareData for queries with aliased parameterized fields #65

Open
edorainos opened this issue May 9, 2017 · 0 comments

Comments

@edorainos
Copy link

Related to #50

Passing preexisting query-payload pairs to prepareData() is messy when the query contains aliased parameterized fields, because Relay modifies the field names to prevent name collisions. To make a preexisting query-response pair for a query containing aliased parameterized fields, I need to use a Relay internal function generateRQLFieldAlias() to produce a valid response. This what I’m doing:

Example query:

const examsQueryNode = Relay.QL`
query ExamsRoute {
    exams {
        SPRING2017: examAverage(term: "SPRING2017")
    }
}
`;

Function to generate response for query-response pair:

import generateRQLFieldAlias from 'react-relay/lib/generateRQLFieldAlias';

function createResponse( examsData ) {
    const preloadedResponse = { exams: {} };
    preloadedResponse.exams[generateRQLFieldAlias('examAverage.SPRING2017.term(SPRING2017)')] = examsData.SPRING2017;
    return preloadedResponse;
}

Does it seem reasonable to submit a pull request to Relay to make a public interface to the generatedRQLFieldAlias() function for this purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant