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

feat: Better graphql-js interop, add mergeSchema to consume external schemas #983

Merged
merged 3 commits into from
Sep 6, 2021

Conversation

tgriesser
Copy link
Member

Fixes: #673, #88, #106, #70

  • Adds a new feature mergeSchema to the makeSchema config, to consume an external schema and merge with the locally defined Nexus types
  • Standardizes the consumption of external GraphQLNamedType's so they are converted into Nexus type definitions, simplifying code paths
  • Order of resolution goes from local Nexus types -> graphql-js types -> external schema types
  • Adds asNexusMethod to all types, allowing for any commonly used types to be used as methods, not just scalars
  • Convert methods / properties from protected -> private in Builder to better detect unused code

config.mergeSchema

export interface MergeSchemaConfig {
  /**
   * GraphQL Schema to merge into the Nexus type definitions.
   *
   * We unwrap each type, preserve the "nullable/nonNull" status of any fields &
   * arguments, and then combine with the local Nexus GraphQL types.
   *
   * If you have multiple schemas
   */
  schema: GraphQLSchema
  /**
   * If we want to "merge" specific types, provide a list of the types you wish to merge here.
   *
   * @default ['Query', 'Mutation']
   */
  mergeTypes?: string[] | true
  /**
   * If there are types that we don't want to include from the external schema in our final
   * Nexus generated schema, provide them here.
   */
  skipTypes?: string[]
  /**
   * If there are certain "fields" that we want to skip, we can specify
   * the fields here and we'll ensure they don't get merged into the schema
   */
  skipFields?: Record<string, string[]>
  /**
   * If there are certain arguments for any type fields that we want to skip, we can specify
   * the fields here & ensure they don't get merged into the final schema.
   *
   * @example
   *   skipArgs: {
   *     Mutation: {
   *       createAccount: ['internalId']
   *     }
   *   }
   */
  skipArgs?: Record<string, Record<string, string[]>>
}

@tgriesser tgriesser merged commit 333dfb8 into main Sep 6, 2021
@tgriesser tgriesser deleted the tgriesser/schema-stitching branch September 6, 2021 13:32
tgriesser added a commit that referenced this pull request Feb 16, 2022
* main:
  chore(docs): fix typos (#1005)
  chore(docs): fix typo 06-chapter-5-persisting-data-via-prisma.mdx (#1007)
  chore(docs): fix typo 04-why-nexus.mdx (#1008)
  chore(docs): fix typo 030-neuxs-framework-prisma-users.mdx (#1016)
  chore(docs): fix typo 05-chapter-4-testing-your-api.mdx (#1023)
  chore(docs): fix typo in 07-chapter-6-testing-with-prisma.mdx (#1024)
  fix: Minimum GraphQL v16 support (#1017)
  chore(docs): add Example Code (#948)
  chore(docs): Update Ordering section (#950)
  chore(docs): Nexus Getting started: missing type in queryType (#995)
  chore(docs): readme update -- fix code sample to include ".ts" in module path (#998)
  chore(docs): typo fix in docs (#999)
  chore(docs): change package get-port ver in tutorial (#1000)
  docs: change all "npm add" to "npm install" (#991)
  docs: Update 061-list-nonNull.mdx (#986)
  feat: Add mergeSchema, better graphql-js interop (#983)
  refactor: More internal cleanup (#981)
  refactor: Internal type cleanup (#980)
  refactor: remove duplicate core schema type checks (#978)
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

Successfully merging this pull request may close these issues.

Allow extendType & extendInputType to extend a GraphQL Type
1 participant