Giter Club home page Giter Club logo

Comments (2)

orta avatar orta commented on July 24, 2024

Not quite figured this, looking like the details come though on the original createVisitor callbacks, but loses the description down the line. For now, I have a pretty solid test that should be green when it all works.

import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from "graphql";
import {GraphQLCompilerContext, IRTransforms, transformASTSchema} from 'relay-compiler'
import * as parseGraphQLText from 'relay-test-utils/lib/parseGraphQLText'
import * as TypeScriptGenerator from '../src/TypeScriptGenerator'

const DogNameDescription = "Ideally short and sweet"

export const NodeInterface = new GraphQLInterfaceType({
  name: "Node",
  description: "An object with a Globally Unique ID",
  fields: () => ({
    id: {
      type: new GraphQLNonNull(GraphQLID),
      description: "The ID of the object.",
    },
  }),
})

const DogType = new GraphQLObjectType({
  name: 'Dog',
  fields: {
    id: { type:  new GraphQLNonNull(GraphQLID) },
    name: { type: GraphQLString, description: DogNameDescription }
  },
  interfaces: [NodeInterface],
})

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      doggo: {
        type: DogType,
        args: {
          id: { type: new GraphQLNonNull(GraphQLID) }
        }
      }
    }
  })
})

test("handles adding the comment on a field", () => {
  const text = `
  fragment HandlesCommentsFragment on Node {
    id
    ... on Dog {
      name
    } 
  }
  `

  const {definitions} = parseGraphQLText(schema, text);
  const tsInterface = new GraphQLCompilerContext(schema, schema)
    .addAll(definitions)
    .applyTransforms(TypeScriptGenerator.transforms)
    .documents()
    .map(doc =>
      TypeScriptGenerator.generate(doc, {
        customScalars: {},
        enumsHasteModule: null,
        existingFragmentNames: new Set(['PhotoFragment']),
        inputFieldWhiteList: [],
        relayRuntimeModule: 'relay-runtime',
        useHaste: true,
      }),
    )
    .join('\n\n');

    expect(tsInterface).toContain(DogNameDescription)
})

from relay-compiler-language-typescript.

kastermester avatar kastermester commented on July 24, 2024

Without having looked too much into it. I think some changes to the relay code might be needed to make this work.

The way I see it, the IR representation should contain the comments. See the TS type definitions here (copy/pasted and adapted from flow code from the relay code): https://github.com/relay-tools/relay-compiler-language-typescript/blob/master/types/graphql-compiler/core/GraphQLIR.d.ts.

But perhaps some dialog with the Relay team is in order wrt. solving this.

from relay-compiler-language-typescript.

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.