{"id":21520117,"url":"https://github.com/mrnkr/ra-data-nestjs-query","last_synced_at":"2025-04-09T22:12:19.069Z","repository":{"id":251979582,"uuid":"839032482","full_name":"mrnkr/ra-data-nestjs-query","owner":"mrnkr","description":"React Admin data provider for nestjs query (graphql)","archived":false,"fork":false,"pushed_at":"2025-02-17T17:53:24.000Z","size":650,"stargazers_count":1,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:12:12.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mrnkr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2024-08-06T20:38:23.000Z","updated_at":"2024-11-26T17:44:56.000Z","dependencies_parsed_at":"2024-11-13T00:21:44.395Z","dependency_job_id":"717cde19-e487-41b3-9fe7-a1837303eb11","html_url":"https://github.com/mrnkr/ra-data-nestjs-query","commit_stats":null,"previous_names":["mrnkr/ra-data-nestjs-query"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrnkr%2Fra-data-nestjs-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrnkr%2Fra-data-nestjs-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrnkr%2Fra-data-nestjs-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrnkr%2Fra-data-nestjs-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrnkr","download_url":"https://codeload.github.com/mrnkr/ra-data-nestjs-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"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-24T01:01:15.098Z","updated_at":"2025-04-09T22:12:19.052Z","avatar_url":"https://github.com/mrnkr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ra-data-nestjs-query\n\n[![npm version](https://badge.fury.io/js/ra-data-nestjs-query.svg)](https://badge.fury.io/js/ra-data-nestjs-query)\n![NPM Downloads](https://img.shields.io/npm/dm/ra-data-nestjs-query)\n[![Node.js CI](https://github.com/mrnkr/ra-data-nestjs-query/actions/workflows/ci.yml/badge.svg)](https://github.com/mrnkr/ra-data-nestjs-query/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/github/mrnkr/ra-data-nestjs-query/branch/master/graph/badge.svg?token=8kjno3xUAy)](https://codecov.io/github/mrnkr/ra-data-nestjs-query)\n![License](https://img.shields.io/github/license/mrnkr/ra-data-nestjs-query)\n\nA GraphQL data provider for [react-admin](https://github.com/marmelab/react-admin/)\nbuilt with [Apollo](https://www.apollodata.com/) and tailored to target a GraphQL API built using [nestjs-query](https://tripss.github.io/nestjs-query/).\n\n- [Installation](#installation)\n- [Usage](#installation)\n- [Options](#options)\n\n## Installation\n\nInstall with:\n\n```sh\nnpm install --save graphql ra-data-nestjs-query\n```\n\nor\n\n```sh\nyarn add graphql ra-data-nestjs-query\n```\n\nor\n\n```sh\npnpm i graphql ra-data-nestjs-query\n```\n\n## Usage\n\nThe `ra-data-nestjs-query` package exposes a single function, which is a constructor for a `dataProvider` based on a GraphQL endpoint. When executed, this function calls the GraphQL endpoint, running an [introspection](https://graphql.org/learn/introspection/) query. It uses the result of this query (the GraphQL schema) to automatically configure the `dataProvider` accordingly.\n\n```jsx\n// in App.js\nimport React from 'react';\nimport { Component } from 'react';\nimport buildGraphQLProvider, { buildQuery } from 'ra-data-nestjs-query';\nimport { Admin, Resource } from 'react-admin';\n\nimport { PostCreate, PostEdit, PostList } from './posts';\n\nconst dataProvider = buildGraphQLProvider({ buildQuery });\n\nconst App = () =\u003e (\n    \u003cAdmin dataProvider={dataProvider} \u003e\n        \u003cResource name=\"Post\" list={PostList} edit={PostEdit} create={PostCreate} /\u003e\n    \u003c/Admin\u003e\n);\n\nexport default App;\n```\n\n**Note**: the parser will generate additional `.id` properties for relation based types. These properties should be used as sources for reference based fields and inputs like `ReferenceField`: `\u003cReferenceField label=\"Author Name\" source=\"author.id\" reference=\"User\"\u003e`.\n\n## Expected GraphQL Schema\n\nThe `ra-data-nestjs-query` function works against GraphQL servers that respect the GraphQL grammar used by [nestjs-query](https://tripss.github.io/nestjs-query/).\n\n## Options\n\n### Customize the Apollo client\n\nYou can either supply the client options by calling `buildGraphQLProvider` like this:\n\n```js\nbuildGraphQLProvider({ clientOptions: { uri: 'http://localhost:4000', ...otherApolloOptions } });\n```\n\nOr supply your client directly with:\n\n```js\nbuildGraphQLProvider({ client: myClient });\n```\n\n### Overriding a specific query\n\nThe default behavior might not be optimized especially when dealing with references. You can override a specific query by wrapping the `buildQuery` function:\n\n```js\n// in src/dataProvider.js\nimport buildGraphQLProvider, { buildQuery } from 'ra-data-nestjs-query';\n\nconst myBuildQuery = introspection =\u003e (fetchType, resource, params) =\u003e {\n    const builtQuery = buildQuery(introspection)(fetchType, resource, params);\n\n    if (resource === 'Command' \u0026\u0026 fetchType === 'GET_ONE') {\n        return {\n            // Use the default query variables and parseResponse\n            ...builtQuery,\n            // Override the query\n            query: gql`\n                query Command($id: ID!) {\n                    data: Command(id: $id) {\n                        id\n                        reference\n                        customer {\n                            id\n                            firstName\n                            lastName\n                        }\n                    }\n                }`,\n        };\n    }\n\n    return builtQuery;\n};\n\nexport default buildGraphQLProvider({ buildQuery: myBuildQuery })\n```\n\n### Customize the introspection\n\nThese are the default options for introspection:\n\n```js\nconst introspectionOptions = {\n    include: [], // Either an array of types to include or a function which will be called for every type discovered through introspection\n    exclude: [], // Either an array of types to exclude or a function which will be called for every type discovered through introspection\n};\n\n// Including types\nconst introspectionOptions = {\n    include: ['Post', 'Comment'],\n};\n\n// Excluding types\nconst introspectionOptions = {\n    exclude: ['CommandItem'],\n};\n\n// Including types with a function\nconst introspectionOptions = {\n    include: type =\u003e ['Post', 'Comment'].includes(type.name),\n};\n\n// Including types with a function\nconst introspectionOptions = {\n    exclude: type =\u003e !['Post', 'Comment'].includes(type.name),\n};\n```\n\n**Note**: `exclude` and `include` are mutually exclusives and `include` will take precedence.\n\n**Note**: When using functions, the `type` argument will be a type returned by the introspection query. Refer to the [introspection](https://graphql.org/learn/introspection/) documentation for more information.\n\nPass the introspection options to the `buildApolloProvider` function:\n\n```js\nbuildApolloProvider({ introspection: introspectionOptions });\n```\n\n## `DELETE_MANY` and `UPDATE_MANY` Optimizations\n\nYour GraphQL backend may not allow multiple deletions or updates in a single query. This provider defaults to simply making multiple requests to handle those. This is obviously not ideal but can be alleviated by supplying your own `ApolloClient` which could use the [apollo-link-batch-http](https://www.apollographql.com/docs/link/links/batch-http.html) link if your GraphQL backend support query batching.\n\n## Contributing\n\nRun the tests with this command:\n\n```sh\npnpm run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrnkr%2Fra-data-nestjs-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrnkr%2Fra-data-nestjs-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrnkr%2Fra-data-nestjs-query/lists"}