Giter Site home page Giter Site logo

Comments (3)

sikanhe avatar sikanhe commented on June 10, 2024

I thought interface already have resolveType
https://github.com/sikanhe/gqtx/blob/master/src/types.ts#L157
https://github.com/sikanhe/gqtx/blob/master/src/define.ts#L215

Alternatively, I think the better way for interface implementation should be using isTypeOf on the subtypes

Quote from graphql creator Lee Byron on this issue:
graphql/graphql-js#876 (comment)

from gqtx.

n1ru4l avatar n1ru4l commented on June 10, 2024

I thought interface already have resolveType
https://github.com/sikanhe/gqtx/blob/master/src/types.ts#L157
https://github.com/sikanhe/gqtx/blob/master/src/define.ts#L215

There is no option for defining the resolveType function with the define API with the interfaceType function:

gqtx/src/define.ts

Lines 224 to 242 in 460bcee

interfaceType<Src>({
name,
description,
fields,
}: {
name: string;
description?: string;
fields: (self: Interface<Ctx, Src | null>) => Array<AbstractField<Ctx, any>>;
}): Interface<Ctx, Src | null> {
const obj: Interface<Ctx, Src | null> = {
kind: 'Interface',
name,
description,
fieldsFn: undefined as any,
};
obj.fieldsFn = () => fields(obj) as any;
return obj;
},

Alternatively, I think the better way for interface implementation should be using isTypeOf on the subtypes

I never heard of that API actually. Looks interesting. and I will definitely check it out. Still, for completeness we should probably still provide the resolveType function option for the interfaceType function.

Unless I have no field that "consumes" the type GraphQLUserChatMessageType or GraphQLOperationalChatMessageType the both types are not available on the GraphQL Schema.

Any ideas on how we can tackle this? Sometimes I only have a field that returns an interface type but the interface implementation types are not directly returned by any field.

A workaround would be to add dummy fields to the Query/Mutation type that return null.

A more clean and clever solution would allow passing in those object types via the buildGraphQLSchema function.

The API could look something like this:

import { buildGraphQLSchema } from "gqtx";
// ... other imports

export const schema = buildGraphQLSchema({
  query: Query,
  subscription: Subscription,
  mutation: Mutation,
  additionalObjectTypes: {
    GraphQLDiceRollOperatorNode,
    GraphQLDiceRollConstantNode,
    GraphQLDiceRollDiceRollNode,
    GraphQLDiceRollOpenParenNode,
    GraphQLDiceRollCloseParenNode,
  }
});

An even more convenient way would be to auto-detect those types by reading the types from unionTypes(Edit: This is already happening right now). This does not work for interface types though.

Therefore the explicit way of passing them to the buildGraphQLSchema function could be the better solution.

from gqtx.

n1ru4l avatar n1ru4l commented on June 10, 2024

I will create a new issue for union types and isTypeOf typing improvements

from gqtx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.