{"_id":"@aacassandra/json-to-graphql-query","name":"@aacassandra/json-to-graphql-query","dist-tags":{"latest":"2.2.5"},"versions":{"2.2.5":{"name":"@aacassandra/json-to-graphql-query","version":"2.2.5","main":"lib/index.js","publishConfig":{"access":"public"},"license":"MIT","author":{"name":"Alauddin Afif Cassandra","email":"alauddinafifcassandra@programmer.net","url":"https://aacassandra-github.web.app"},"scripts":{"build":"tslint -p . && rm -rf lib/ && tsc","test":"mocha -r ts-node/register --recursive \"./src/**/__tests__/*\"","test-watch":"mocha -r ts-node/register --recursive \"./src/**/__tests__/*\" --watch --watch-extensions ts,tsx","prepare":"npm run build && npm run test"},"typings":"lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/aacassandra/json-to-graphql-query.git"},"devDependencies":{"@types/chai":"4.3.0","@types/mocha":"9.1.0","@types/node":"16.11.22","chai":"4.3.6","mocha":"9.2.0","sinon":"13.0.1","ts-node":"10.4.0","tslint":"6.1.3","typescript":"4.5.5","ansi-regex":"6.0.1"},"gitHead":"a8805edfa02384cd376c316ff30536bef8e6cd9b","description":"This is a simple module that takes a JavaScript object and turns it into a GraphQL query to be sent to a GraphQL server.","bugs":{"url":"https://github.com/aacassandra/json-to-graphql-query/issues"},"homepage":"https://github.com/aacassandra/json-to-graphql-query#readme","_id":"@aacassandra/json-to-graphql-query@2.2.5","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-Iwv57zwhU9u24DQTrSkc4+pt80zUg/0/LDIzhjgQkPM0i9iMlNQOr+F0f92W06JIqejU7PkmQqADCMqM+Og7Gg==","shasum":"06ad4c6324a035e498c2ed82a96101d86d9ee7bd","tarball":"https://registry.npmjs.org/@aacassandra/json-to-graphql-query/-/json-to-graphql-query-2.2.5.tgz","fileCount":21,"unpackedSize":34341,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBfwlIsxQsjp1uwKUi/b24gmQPI+sjSs3WmzjOzPfC0yAiABw/TgQM4kgW95COX4KMkFUrapxflPooiON2egqe5rBQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjHf32ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp4Ow/+MOPgIesbIV9OdvrQswHZh2C0+xs4BiyEdaF4FFvFE7r/r6xh\r\nh8i7fF+Cs/8te5luCLYIRc23ZNRQ18Q6m1pVJP+CEMM+1sl80+ebL286kFOr\r\n+p3Nq7NHQiaCUKi/fXpRHaCl57ideBJxTa2ARdkGs+rYxRi2427y6G30Rczv\r\np22Et4xd6DYWswu6iWwNo6Zr7+ur0+CMqJ7Bxn/3aP5H6qMdjkMaZuIjQ4lG\r\n7aDNlqiD7CRqMEeIOrjQW+kgyXlIvwikaS0Fq2RnTntLgH2C9QkePsZ6Wdio\r\nF9As8Fa5S6jwv9FoAlTj/8CwqydRFfyX6PzRnnhTzJBoW7RmxoGxPyOedFRR\r\nFbAeBYVPWmKk+H+clmo9MPB9/bOf5e6Jhfycs0sDCCz83evj+V6ll/zkh5HB\r\nvFDKICYHD9Ena2B1lOJK+p1GO/ezMejsJ3UhRL/eWRfJJocarymSQ3OTlFta\r\nJy7PtiC3XmRX0qBtqrPPgLhqrEDVCg3JSNzd2lmiWFuJTgS+02RlKzq5OUQF\r\nC35M4ItTXnvZDqdziPs1PiktfWs99quUKElajYLeiIMChsOlUEnSFNDubekg\r\n364zGHU/HeFGPgBy7NjsvmgRfNvna8QduDalmRQS3aYU7N4WBI/VvWAZZhrp\r\n+FROBMwrFnkWlgzNuEda0CTMzC7xZXW7c5c=\r\n=uaw6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"aacassandra","email":"alauddinafifcassandra@programmer.net"},"directories":{},"maintainers":[{"name":"aacassandra","email":"alauddinafifcassandra@programmer.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-to-graphql-query_2.2.5_1662909942285_0.3046598326169323"},"_hasShrinkwrap":false}},"time":{"created":"2022-09-11T15:25:42.174Z","2.2.5":"2022-09-11T15:25:42.440Z","modified":"2022-09-11T15:25:42.555Z"},"maintainers":[{"name":"aacassandra","email":"alauddinafifcassandra@programmer.net"}],"description":"This is a simple module that takes a JavaScript object and turns it into a GraphQL query to be sent to a GraphQL server.","homepage":"https://github.com/aacassandra/json-to-graphql-query#readme","repository":{"type":"git","url":"git+https://github.com/aacassandra/json-to-graphql-query.git"},"author":{"name":"Alauddin Afif Cassandra","email":"alauddinafifcassandra@programmer.net","url":"https://aacassandra-github.web.app"},"bugs":{"url":"https://github.com/aacassandra/json-to-graphql-query/issues"},"license":"MIT","readme":"# json-to-graphql-query\n\nThis is a simple module that takes a JavaScript object and turns it into a\nGraphQL query to be sent to a GraphQL server.\n\nMainly useful for applications that need to generate graphql queries dynamically.\n\n## New Maintainer!\n\nHuge thanks to @vkolgi for agreeing to take over maintenance of this library! I look forward to\nfollowing its continued development. - @dupski\n\n## Installation\n\n```\nnpm install json-to-graphql-query\n```\n\n## Usage\n\n```ts\nconst query = jsonToGraphQLQuery(queryObject: object, options?: object);\n```\n\nSupported Options:\n * `pretty` - boolean - optional - set to `true` to enable pretty-printed output\n * `ignoreFields` - string[] - optional - you can pass an array of object key names that you want removed from the query\n * `includeFalsyKeys` - boolean - optional - disable the default behaviour if excluding keys with a falsy value\n\n## Features\n\n * Converts a JavaScript object to a GraphQL Query string\n * Full support for nested query / mutation nodes and arguments\n * Optionally strip specific object keys using the `ignoreFields` option\n * Support for input arguments via [`__args`](#query-with-arguments)\n * Support for query aliases via [`__aliasFor`](#using-aliases)\n * Support for Enum values via [`EnumType`](#query-with-enum-values)\n * Support for variables via [`__variables`](#query-with-variables)\n * Support for simple directives (such as `@client`) via [`__directives`](#query-with-directives)\n * Support for one or more inline fragments via [`__on.__typeName`](#query-with-inline-fragments)\n * Support for full fragments via [`__all_on`](#query-with-inline-fragments)\n * Support for named queries/mutations via [`__name`](#query-with-name)\n\n## Recent Changes\n\nSee the [CHANGELOG](CHANGELOG.md)\n\n### Simple Query\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            id: true,\n            title: true,\n            post_date: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        id\n        title\n        post_date\n    }\n}\n```\n\n### Query with arguments\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            __args: {\n                where: { id: 2 }\n                orderBy: 'post_date'\n            },\n            id: true,\n            title: true,\n            post_date: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts (where: {id: 2}, orderBy: \"post_date\") {\n        id\n        title\n        post_date\n    }\n}\n```\n\n### Query with nested objects\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            id: true,\n            title: true,\n            comments: {\n                id: true,\n                comment: true,\n                user: true\n            }\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        id\n        title\n        comments {\n            id\n            comment\n            user\n        }\n    }\n}\n```\n\n### Query with disabled fields\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            id: true,\n            title: false,\n            comments: {\n                id: true,\n                comment: false,\n                user: true\n            }\n        },\n        User: false\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        id\n        comments {\n            id\n            user\n        }\n    }\n}\n```\nNOTE: You can tell jsonToGraphQLQuery() not to exclude keys with a falsy value\nby setting the `includeFalsyKeys` option.\n\n### Using aliases\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        allPosts: {\n            __aliasFor: 'Posts',\n            id: true,\n            comments: {\n                id: true,\n                comment: true\n            }\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    allPosts: Posts {\n        id\n        comments {\n            id\n            comment\n        }\n    }\n}\n```\n\n### Query with Enum Values\n\n```typescript\nimport { jsonToGraphQLQuery, EnumType } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            __args: {\n                orderBy: 'post_date',\n                status: new EnumType('PUBLISHED')\n            },\n            title: true,\n            body: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts (orderBy: \"post_date\", status: PUBLISHED) {\n        title\n        body\n    }\n}\n```\n\n### Query with variables\n\n```typescript\nimport { jsonToGraphQLQuery, VariableType } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        __variables: {\n            variable1: 'String!',\n            variableWithDefault: 'String = \"default_value\"'\n        },\n        Posts: {\n            __args: {\n                arg1: 20,\n                arg2: new VariableType('variable1')\n            },\n            id: true,\n            title: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery ($variable1: String!, $variableWithDefault: String = \"default_value\") {\n    Posts (arg1: 20, arg2: $variable1) {\n        id\n        title\n    }\n}\n```\n\n### Query with Directives\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        __directives: {\n            client: true\n        }\n        Posts: {\n            id: true,\n            title: true,\n            post_date: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts @client {\n        id\n        title\n        post_date\n    }\n}\n```\n\n### Ignoring fields in the query object\n\nWe sometimes want to ignore specific fields in the initial object, for instance __typename in Apollo queries.\nYou can specify these fields using the `ignoreFields` option:\n\n```typescript\nimport { jsonToGraphQLQuery, VariableType } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            shouldBeIgnored: {\n                variable1: 'a value'\n            },\n            id: true,\n            title: true,\n            post_date: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, {\n    pretty: true,\n    ignoreFields: ['shouldBeIgnored']\n});\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        id\n        title\n        post_date\n    }\n}\n```\n\n### Query with Inline Fragments\n\nFull inline fragments\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            title: true,\n            __all_on: [\n                \"ConfigurablePost\",\n                \"PageInfo\"\n            ]\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        title\n        ...ConfigurablePost\n        ...PageInfo\n    }\n}\n```\n\nPartial inline fragments\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        Posts: {\n            title: true,\n            __on: {\n                __typeName: \"ConfigurablePost\",\n                id: true\n            }\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        title\n        ... on ConfigurablePost {\n            id\n        }\n    }\n}\n```\n\n### Query with multiple Inline Fragments\n\n```typescript\nimport { jsonToGraphQLQuery } from 'json-to-graphql-query';\n\nconst query = {\n            query: {\n                Posts: {\n                    __on: [\n                    {\n                        __typeName: \"ConfigurablePost\",\n                        id: true\n                    },\n                    {\n                        __typeName: \"UnconfigurablePost\",\n                        name: true\n                    }]\n                }\n            }\n        };\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\nResulting `graphql_query`\n\n```graphql\nquery {\n    Posts {\n        title\n        ... on ConfigurablePost {\n            id\n        }\n        ... on UnconfigurablePost {\n            name\n        }\n    }\n}\n```\n\n### Query with name\n\n```typescript\nimport { jsonToGraphQLQuery, VariableType } from 'json-to-graphql-query';\n\nconst query = {\n    query: {\n        __name: 'NewName',\n        __variables: {\n            variable1: 'String!',\n            variableWithDefault: 'String = \"default_value\"'\n        },\n        Posts: {\n            __args: {\n                arg1: 20,\n                arg2: new VariableType('variable1')\n            },\n            id: true,\n            title: true\n        }\n    }\n};\nconst graphql_query = jsonToGraphQLQuery(query, { pretty: true });\n```\n\nResulting `graphql_query`\n\n```graphql\nquery NewName ($variable1: String!, $variableWithDefault: String = \"default_value\") {\n    Posts (arg1: 20, arg2: $variable1) {\n        id\n        title\n    }\n}\n```\n\n## TO-DO List\n\n * Probably some other things!...\n\nPull requests welcome!\n\n## License\n\nMIT\n","readmeFilename":"README.md"}