Coder Social home page Coder Social logo

Comments (8)

Leksat avatar Leksat commented on June 12, 2024 1

Could someone take a look at the PR? #87

from gatsby-graphql-toolkit.

vladar avatar vladar commented on June 12, 2024

I skimmed through code and don't see how this can happen. Can you provide some quick reproduction project for further investigation?

from gatsby-graphql-toolkit.

vladar avatar vladar commented on June 12, 2024

Type conversion usually happens here:

function toGatsbyType(
context: ISchemaCustomizationContext,
remoteType: GraphQLType
) {
const namedType = getNamedType(remoteType)
const gatsbyTypeName = context.typeNameTransform.toGatsbyTypeName(
namedType.name
)
return wrap(gatsbyTypeName, remoteType)
}
/**
* Wraps a type with the NON_NULL and LIST_OF types of the referenced remote type
* i.e. wrapType(`JSON`, myRemoteListOfJSONType) => `[JSON]`
*/
function wrap(typeName: string, remoteType: GraphQLType): string {
let wrappedType = typeName
let currentRemoteType = remoteType
while (isWrappingType(currentRemoteType)) {
if (isListType(currentRemoteType)) {
wrappedType = `[${wrappedType}]`
}
if (isNonNullType(currentRemoteType)) {
wrappedType = `${wrappedType}!`
}
currentRemoteType = currentRemoteType.ofType
}
return wrappedType
}

from gatsby-graphql-toolkit.

feedm3 avatar feedm3 commented on June 12, 2024

Better late than never 😄 The issue is still there so I took some time to create a reproduction project.

I couldn't make the request from the CodeSandbox Gatsby project to the GraphQL project work. You can download both projects as .zip file (CodeSandbox > Menu > File > Export to ZIP) and run them locally without any further adjustments.

GraphQL Server

The GraphQL server has a minimal schema with 2 lists. One with mandatory entries and one with optional entries:

type Todo {
  id: ID!
  ...
  mandatoryTextEntries: [String!]!
  optionalTextEntries: [String]!
}

The schema is also correct in the GraphiQL client:
grafik

Test data is already setup so running the query

query getTodos {
  todos {
    mandatoryTextEntries
    optionalTextEntries
  }
}

will return the following valid result:

{
  "data": {
    "todos": [
      {
        "mandatoryTextEntries": [
          "entry 1",
          "entry 2"
        ],
        "optionalTextEntries": [
          "entry 1",
          "entry 2",
          null,
          "entry 4"
        ]
      },
      {
        "mandatoryTextEntries": [],
        "optionalTextEntries": []
      }
    ]
  }
}

Gatsby client

The data gets sources by the toolkit in gatsby-node.js.

Starting the development server, the ExmapleTodo type is available. Looking closer to the fields in the GraphiQl client reveals, that the optionalTextEntries list now has mandatory entries. Also, the list itself is now optional:

grafik

As example data has one null entry in the optionalTextEntries array, this query

query getTodos {
  allExampleTodo {
    nodes {
      mandatoryTextEntries
      optionalTextEntries
    }
  }
}

results in an error, as there are no optional entries allowed anymore:

grafik

I hope I can help find the bug 🙂

from gatsby-graphql-toolkit.

Leksat avatar Leksat commented on June 12, 2024

Confirming. Source field: [Type]! is translated to field: [Type!].

from gatsby-graphql-toolkit.

andrezimpel avatar andrezimpel commented on June 12, 2024

Can confirm. Schema customization doesn't seam to be a way to work around this.

from gatsby-graphql-toolkit.

andrezimpel avatar andrezimpel commented on June 12, 2024

Type conversion usually happens here:

function toGatsbyType(
context: ISchemaCustomizationContext,
remoteType: GraphQLType
) {
const namedType = getNamedType(remoteType)
const gatsbyTypeName = context.typeNameTransform.toGatsbyTypeName(
namedType.name
)
return wrap(gatsbyTypeName, remoteType)
}
/**
* Wraps a type with the NON_NULL and LIST_OF types of the referenced remote type
* i.e. wrapType(`JSON`, myRemoteListOfJSONType) => `[JSON]`
*/
function wrap(typeName: string, remoteType: GraphQLType): string {
let wrappedType = typeName
let currentRemoteType = remoteType
while (isWrappingType(currentRemoteType)) {
if (isListType(currentRemoteType)) {
wrappedType = `[${wrappedType}]`
}
if (isNonNullType(currentRemoteType)) {
wrappedType = `${wrappedType}!`
}
currentRemoteType = currentRemoteType.ofType
}
return wrappedType
}

@vladar so does this mean isListType or isNonNullType is not correct, right?

from gatsby-graphql-toolkit.

Leksat avatar Leksat commented on June 12, 2024

A release? 🙏

(This is a really confusing bug 😅)

from gatsby-graphql-toolkit.

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.