### Example Input GraphQL Schema Files (GraphQL) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Illustrative examples of GraphQL schema files located in different directories, intended to be merged by the utility. ```graphql ~/moduleMain/schemas/Root.graphql: type Query; ~/module1/schemas/Book.graphql: extend type Query { bookById(id: ID!): Book } type Book { id: ID! authorId: ID! } ~/module2/schemas/User.graphql: extend type Query { userById(id: ID!): User } type User { id: ID! name: String! } ``` -------------------------------- ### Installing graphql-schema-utilities CLI (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Command to install the graphql-schema-utilities CLI tool globally using npm. ```sh npm install -g graphql-schema-utilities ``` -------------------------------- ### Example Merged GraphQL Schema Output (GraphQL) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Illustrative example of the resulting merged GraphQL schema file generated by the utility from the input schema files. ```graphql type Query { userById(id: ID!): User bookById(id: ID!): Book } type User { id: ID! name: String! } type Book { id: ID! authorId: ID! } ``` -------------------------------- ### Install Dependencies (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Installs project dependencies using the npm package manager. This command reads the `package.json` file and downloads the necessary packages into the `node_modules` directory. ```sh npm install ``` -------------------------------- ### Implementing a Custom GraphQL Validation Rule (TypeScript) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Example TypeScript code for creating a custom validation rule that checks if GraphQL operation names start with "Hawaii_". This rule can be used with the graphql-schema-utilities tool. ```typescript import { GraphQLError } from 'graphql'; export function doesNotStartWithHawaii(operationName: string): string { return `"${operationName}" operation does not start with Hawaii_.`; } /** * Valid only if it starts with Hawaii_. * A GraphQL document is only valid if all defined operations starts with Hawaii_. */ export function OperationNameStartsWithHawaii( context: any, ): any { const knownOperationNames = Object.create(null); return { OperationDefinition(node) { const operationName = node.name; if (operationName) { if (!operationName.value.startsWith('Hawaii_')) { context.reportError( new GraphQLError( doesNotStartWithHawaii(operationName.value) ), ); } else { knownOperationNames[operationName.value] = operationName; } } return false; }, FragmentDefinition: () => false, }; } ``` -------------------------------- ### Run Build Script (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Executes the 'build' script defined in the project's `package.json` file. This is typically used to compile, bundle, or process source code for distribution. ```sh npm run build ``` -------------------------------- ### Running graphql-schema-utilities CLI (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Basic command to execute the graphql-schema-utilities CLI tool. It will attempt to merge schemas and validate operations based on default or configured paths. ```sh >> graphql-schema-utilities ``` -------------------------------- ### Using a Custom Validation Rule with CLI (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Command demonstrating how to apply a custom validation rule file (compiled JavaScript) to the validation process using the -r option. ```sh >> graphql-schema-utilities -s "{./First_Directory/**/*.graphql,./Second_Directory/users/**/*.graphql}" -p "./path_to_directory/operations/*.graphql" -r "path/to/custom_rule.js" ``` -------------------------------- ### Merging GraphQL Schema Files (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Command demonstrating how to merge GraphQL schema files from multiple directories using glob patterns with the -s option. ```sh >> graphql-schema-utilities -s "{./First_Directory/**/*.graphql,./Second_Directory/users/**/*.graphql}" ``` -------------------------------- ### Run Tests in Watch Mode (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Executes the 'test:watch' script defined in the project's `package.json` file. This command typically runs tests and watches for file changes, re-running tests automatically when changes are detected. ```sh npm run test:watch ``` -------------------------------- ### Merge GraphQL Schemas using graphql-schema-utilities (JS) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Demonstrates how to programmatically merge multiple GraphQL schema files using the `mergeGQLSchemas` function from the `graphql-schema-utilities` library. It takes a glob pattern as input and returns a promise that resolves with the merged schema or rejects with an error. ```js const tools = require('graphql-schema-utilities'); const glob = "{./First_Directory/**/*.graphql,./Second_Directory/users/**/ *.graphql}" tools.mergeGQLSchemas(glob).then((schema) => { console.log('schema files were merged, and the valid schema is: ', schema) }) .catch((error) => { console.error(error) }) ``` -------------------------------- ### Validating GraphQL Operations (Shell) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Command demonstrating how to validate GraphQL operation files against a merged schema using glob patterns with the -s and -p options. ```sh >> graphql-schema-utilities -s "{./First_Directory/**/*.graphql,./Second_Directory/users/**/*.graphql}" -p "./path_to_directory/operations/*.graphql" ``` -------------------------------- ### Validate GraphQL Operations using graphql-schema-utilities (JS) Source: https://github.com/awslabs/graphql-schema-utilities/blob/master/README.md Shows how to validate GraphQL operations against a merged schema. It first merges schema files, then uses the resulting schema to validate query files specified by another glob pattern, logging the validation results. ```js tools.mergeGQLSchemas('./schema/*.graphql').then((schema) => { tools.validateOperations('./queries/*.graphql', schema).then((results) => { console.log(results) }) }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.