Detalhes do pacote

@pothos/plugin-simple-objects

hayes113.2kISC4.1.3

A Pothos plugin for defining objects and interfaces without ts definitions for those types

pothos, graphql, schema, typescript

readme (leia-me)

Simple Objects Plugin for Pothos

The Simple Objects Plugin provides a way to define objects and interfaces without defining type definitions for those objects, while still getting full type safety.

Usage

Install

yarn add @pothos/plugin-simple-objects

Setup

import SimpleObjectsPlugin from '@pothos/plugin-simple-objects';
const builder = new SchemaBuilder({
  plugins: [SimpleObjectsPlugin],
});

Example

import SchemaBuilder from '@pothos/core';
import SimpleObjectsPlugin from '@pothos/plugin-simple-objects';

const builder = new SchemaBuilder({
  plugins: [SimpleObjectsPlugin],
});

const ContactInfo = builder.simpleObject('ContactInfo', {
  fields: (t) => ({
    email: t.string({
      nullable: false,
    }),
    phoneNumber: t.string({
      nullable: true,
    }),
  }),
});

const Node = builder.simpleInterface('Node', {
  fields: (t) => ({
    id: t.id({
      nullable: false,
    }),
  }),
});

const UserType = builder.simpleObject(
  'User',
  {
    interfaces: [Node],
    fields: (t) => ({
      firstName: t.string(),
      lastName: t.string(),
      contactInfo: t.field({
        type: ContactInfo,
        nullable: false,
      }),
    }),
  },
  // You can add additional fields with resolvers with a third fields argument
  (t) => ({
    fullName: t.string({
      resolve: (user) => `${user.firstName} ${user.lastName}`,
    }),
  }),
);

builder.queryType({
  fields: (t) => ({
    user: t.field({
      type: UserType,
      args: {
        id: t.arg.id({ required: true }),
      },
      resolve: (parent, args, { User }) => {
        return {
          id: '1003',
          firstName: 'Leia',
          lastName: 'Organa',
          contactInfo: {
            email: 'leia@example.com',
            phoneNumber: null,
          },
        };
      },
    }),
  }),
});

Extending simple objects

In some cases, you may want to add more complex fields with resolvers or args where the value isn't just passed down from the parent.

In these cases, you can either add the field in the 3rd arg (fields) as shown above, or you can add additional fields to the type using methods like builder.objectType:

builder.objectType(UserType, (t) => ({
  fullName: t.string({
    resolve: (user) => `${user.firstName} ${user.lastName}`,
  }),
}));

Limitations

When using simpleObjects in combination with other plugins like authorization, those plugins may use unknown as the parent type in some custom fields (eg. parent of a permission check function on a field).

changelog (log de mudanças)

Change Log

4.1.3

Patch Changes

  • 1622740: update dependencies

4.1.2

Patch Changes

  • cd7f309: Update dependencies

4.1.1

Patch Changes

  • d874bce: Improve inference of multiple interfaces

4.1.0

Minor Changes

  • 27af377: replace eslint and prettier with biome

4.0.3

Patch Changes

  • Updated dependencies [777f6de]
    • @pothos/core@4.0.2

4.0.2

Patch Changes

  • 9bd203e: Fix graphql peer dependency version to match documented minumum version
  • Updated dependencies [9bd203e]
    • @pothos/core@4.0.1

4.0.1

Patch Changes

  • d4f7705: Allow extending interfaces without re-defining all fields

4.0.0

Major Changes

Patch Changes

  • c1e6dcb: update readmes
  • Updated dependencies [c1e6dcb]
  • Updated dependencies [29841a8]
    • @pothos/core@4.0.0

4.0.0-next.1

Patch Changes

  • update readmes
  • Updated dependencies
    • @pothos/core@4.0.0-next.1

4.0.0-next.0

Major Changes

Patch Changes

  • Updated dependencies [29841a8]
    • @pothos/core@4.0.0-next.0

3.7.1

Patch Changes

  • 1ecea46: revert accidental pinning of graphql peer dependency

3.7.0

Minor Changes

  • 740f09c6: Add fields as 3rd argument for simpleObject and simpleInterface

3.6.8

Patch Changes

  • 4c6bc638: Add provinance to npm releases

3.6.7

Patch Changes

  • d4d41796: Update dev dependencies

3.6.6

Patch Changes

  • 6f00194c: Fix an issue with esm import transform

3.6.5

Patch Changes

  • b12f9122: Fix issue with esm build script

3.6.4

Patch Changes

  • 9fa27cf7: Transform dynamic type imports in d.ts files

3.6.3

Patch Changes

  • 3a82d645: Apply esm transform to esm d.ts definitions

3.6.2

Patch Changes

  • 218fc68b: Fix script for copying ems d.ts definitions

3.6.1

Patch Changes

  • 67531f1e: Create separate typescript definitions for esm files

3.6.0

Minor Changes

  • 11929311: Update type definitions to work with module: "nodeNext"

3.5.1

Patch Changes

  • aa18acb7: update dev dependencies

3.5.0

Minor Changes

  • d67764b5: Make options objecst on toSchema, queryType, and mutationType optional

3.4.0

Minor Changes

  • 3a7ff291: Refactor internal imports to remove import cycles

Patch Changes

  • 3a7ff291: Update dev dependencies

3.3.0

Minor Changes

  • ecb2714c: Add types entry to export map in package.json and update dev dependencies

    This should fix compatibility with typescripts new "moduleResolution": "node12"

3.2.0

Minor Changes

  • 241a385f: Add peer dependency on @pothos/core

3.1.0

Minor Changes

  • 6279235f: Update build process to use swc and move type definitions to dts directory

Patch Changes

  • 21a2454e: update dev dependencies

3.0.3

Patch Changes

  • 03aecf76: update .npmignore

3.0.2

Patch Changes

  • 43ca3031: Update dev dependencies

3.0.1

Patch Changes

  • 2d9b21cd: Use workspace:* for dev dependencies on pothos packages

3.0.0

Major Changes

  • 4caad5e4: Rename GiraphQL to Pothos

2.13.0

Minor Changes

  • 9307635a: Migrate build process to use turborepo

2.12.1

Patch Changes

  • c6aa732: graphql@15 type compatibility fix

2.12.0

Minor Changes

  • 6d6d54e: Add complexity plugin

2.11.1

Patch Changes

  • c85dc33: Add types entry in package.json

2.11.0

Minor Changes

  • aeef5e5: Update dependencies

2.10.0

Minor Changes

  • 9107f29: Update dependencies (includes graphql 16)

2.9.0

Minor Changes

  • 17db3bd: Make type refs extendable by plugins

2.8.2

Patch Changes

  • c976bfe: Update dependencies

2.8.1

Patch Changes

  • 4150f92: Fixed esm transformer for path-imports from dependencies

2.8.0

Minor Changes

  • dc87e68: update esm build process so extensions are added during build rather than in source

2.7.1

Patch Changes

  • b4b8381: Updrade deps (typescript 4.4)

2.7.0

Minor Changes

  • a4c87cf: Use ".js" extensions everywhere and add module and exports to package.json to better support ems in node

2.6.2

Patch Changes

  • f13208c: bump to fix latest tag

2.6.1

Patch Changes

  • 9ab8fbc: re-release previous version due to build-process issue

2.6.0

Minor Changes

  • 3dd3ff14: Updated dev dependencies, switched to pnpm, and added changesets for releases

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.5.1 - 2021-08-03

Note: Version bump only for package @giraphql/plugin-simple-objects

2.5.1-alpha.0 - 2021-08-02

Note: Version bump only for package @giraphql/plugin-simple-objects

2.5.0 - 2021-07-30

🚀 Updates

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.4 - 2021-07-23

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.4-alpha.0 - 2021-07-17

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.3 - 2021-07-10

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.2 - 2021-07-04

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.2-alpha.0 - 2021-07-04

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.1 - 2021-07-02

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.0 - 2021-06-28

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.0-alpha.1 - 2021-06-28

Note: Version bump only for package @giraphql/plugin-simple-objects

2.4.0-alpha.0 - 2021-06-28

🚀 Updates

Note: Version bump only for package @giraphql/plugin-simple-objects

2.3.0 - 2021-06-11

🚀 Updates

  • make field options args optional when empty (ae71648)

📦 Dependencies

🛠 Internals

Note: Version bump only for package @giraphql/plugin-simple-objects

2.2.0 - 2021-06-10

Note: Version bump only for package @giraphql/plugin-simple-objects

2.2.0-alpha.0 - 2021-06-09

🚀 Updates

  • plum parentShape through all ussage of output refs (2dac2ca)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.5 - 2021-05-18

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.4 - 2021-05-13

📘 Docs

  • add docs for loadableNode (1ae01e8)

🛠 Internals

  • add tests for loadableNode (c1b49a0)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.3 - 2021-05-12

🛠 Internals

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.2 - 2021-05-10

🐞 Fixes

  • update ci build command (7e1d1d2)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.1 - 2021-05-10

🐞 Fixes

  • force new version to fix esm build issue (25f1fd2)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.1.0 - 2021-05-10

🚀 Updates

  • add esm build for all packages (d8bbdc9)

📘 Docs

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.3 - 2021-05-02

🛠 Internals

  • force version bumps and update validation to 2.0 range (07730b3)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.2 - 2021-04-16

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.2-alpha.0 - 2021-04-12

📦 Dependencies

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.1 - 2021-02-19

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.0 - 2021-02-16

💥 Breaking

  • update plugin API to avoid modifying args. subGraphs are now build by passing subGraph to toSchema (66d456e)
  • update plugin exports and names to be more consistent (ee07b35)

📦 Dependencies

  • update dependencies and add license files (cb0d102)

📘 Docs

  • add more docs o writing plugins (b996fc6)

Note: Version bump only for package @giraphql/plugin-simple-objects

2.0.0-alpha.1 - 2021-02-10

🛠 Internals

  • bump simple-objects to 2.0 (2ee091a)

Note: Version bump only for package @giraphql/plugin-simple-objects

1.2.2-alpha.0 - 2021-02-10

🛠 Internals

Note: Version bump only for package @giraphql/plugin-simple-objects

1.2.1 - 2021-02-07

🐞 Fixes

  • specify @giraphql/core as peer and dev dep so it is updated correctly (f096393)

Note: Version bump only for package @giraphql/plugin-simple-objects

1.1.0 (2020-10-21)

Note: Version bump only for package @giraphql/plugin-simple-objects

Changelog

1.0.0

Initial release