{"id":21043478,"url":"https://github.com/errorpro/relay-context-provider","last_synced_at":"2025-03-13T21:44:40.505Z","repository":{"id":91171808,"uuid":"167202799","full_name":"ErrorPro/relay-context-provider","owner":"ErrorPro","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-23T15:09:45.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T17:24:21.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ErrorPro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-23T15:08:57.000Z","updated_at":"2019-01-23T15:09:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"a6c27ebc-90fa-4354-9932-8df9e3329342","html_url":"https://github.com/ErrorPro/relay-context-provider","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErrorPro%2Frelay-context-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErrorPro%2Frelay-context-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErrorPro%2Frelay-context-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErrorPro%2Frelay-context-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ErrorPro","download_url":"https://codeload.github.com/ErrorPro/relay-context-provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489807,"owners_count":20298997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T14:13:00.814Z","updated_at":"2025-03-13T21:44:40.496Z","avatar_url":"https://github.com/ErrorPro.png","language":"JavaScript","readme":"# relay-context-provider\nAdds relay environment and variables to React Context. Use then when you are fetching queries manually and need to render `fragmentContainers`. This is useful for server side rendering. \n\n## Install\nyarn add relay-context-provider\n\n## Usage\n```js\n\nimport {fetchQuery} from 'react-relay';\nimport RelayContextProvider from 'relay-context-provider';\nimport React from 'react';\nimport ReactDOMServer from 'react-dom/server';\n\nasync function (res, req, next) {\n    const data = await fetchQuery(environment, query, res.query);\n    const html = ReactDOMServer.renderToString(\n        \u003cRelayContextProvider\n            environment={environment}\n            variables={res.query}\n        \u003e\n            \u003cMyComponent {...data} /\u003e\n        \u003c/RelayContextProvider\u003e\n    );\n\n    return html;\n});\n```\n\n```js\n\nimport React from 'react';\nimport {QueryRenderer} from 'react-relay';\nimport {withRelay} from 'relay-context-provider';\n\nconst MyComponent = ({relay}) =\u003e {\n  return \u003cQueryRenderer\n    environment={relay.environment}\n    query={graphql`\n      query MyComponentQuery {\n        viewer {\n          fullName\n        }\n      }\n    `}\n    variables={{}}\n    render={({error, props}) =\u003e {\n      if (error) {\n        return \u003cdiv\u003eError\u003c/div\u003e;\n      }\n      if (!props) {\n        return \u003cdiv\u003eLoading\u003c/div\u003e;\n      }\n      return \u003cdiv\u003eGot viewer: {props.viewer.fullName}\u003c/div\u003e;\n    }}\n  /\u003e;\n};\n\nexport default withRelay(MyComponent);\n```\n\n### Isomorphic Example\nSee the full isomorphic/universal/server side rendered example here: https://github.com/robrichard/relay-modern-isomorphic-example\n\n## Running Tests\n\n```bash\nyarn test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrorpro%2Frelay-context-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferrorpro%2Frelay-context-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrorpro%2Frelay-context-provider/lists"}