2.13.0 • Published 2 years ago

@giraphql/plugin-simple-objects v2.13.0

Weekly downloads
145
License
ISC
Repository
github
Last release
2 years ago

Simple Objects Plugin for GiraphQL

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 @giraphql/plugin-simple-objects

Setup

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

Example

import SchemaBuilder from '@giraphql/core';
import SimpleObjectsPlugin from '@giraphql/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,
    }),
  }),
});

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,
          },
        };
      },
    }),
  }),
});

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).

2.13.0

2 years ago

2.12.1

2 years ago

2.11.0

2 years ago

2.11.1

2 years ago

2.12.0

2 years ago

2.10.0

3 years ago

2.9.0

3 years ago

2.8.2

3 years ago

2.8.1

3 years ago

2.8.0

3 years ago

2.7.1

3 years ago

2.7.0

3 years ago

2.6.2

3 years ago

2.6.1

3 years ago

2.6.0

3 years ago

2.5.1

3 years ago

2.5.1-alpha.0

3 years ago

2.5.0

3 years ago

2.4.4

3 years ago

2.4.4-alpha.0

3 years ago

2.4.3

3 years ago

2.4.2-alpha.0

3 years ago

2.4.2

3 years ago

2.4.1

3 years ago

2.4.0-alpha.1

3 years ago

2.4.0

3 years ago

2.4.0-alpha.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.2.0-alpha.0

3 years ago

2.1.2

3 years ago

2.0.3

3 years ago

2.1.1

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.5

3 years ago

2.1.0

3 years ago

2.0.2

3 years ago

2.0.2-alpha.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.2-alpha.0

3 years ago

2.0.0-alpha.1

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.1.0-alpha.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago