question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when fragments are separated

See original GitHub issue

Currently when fragments are stored separately from queries and mutations, the codegen produces a “Unknown fragment …” error.

Example:

fragment.ts

import gql from 'graphql-tag';

export const userInfo = gql`
  fragment UserInfo on User {
    id
    name
    email
  }
`;

query.ts

import gql from 'graphql-tag';

import { userInfo } from './fragment.ts';

export const userQuery = gql`
  query UserQuery($id: ID!) {
    user(id: $id) {
      ...UserInfo
    }
  }

  ${userInfo}
`;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dotansimhacommented, Apr 10, 2019

@LawJolla In 1.0.7 we fixed that, now you’ll get a more readable error with the missing fragment name. If you are still having issues, please open a new issue because this one is closed and outdated.

0reactions
LawJollacommented, Apr 8, 2019

I’m getting this error. Version 1.0.6 with 1.0.6 versions of typescript and typescript-react-apollo

Works

// query.ts

const DealFragment = gql`
  fragment DealFragment on Deal {
    id
  }
`

const DEALS_FOR_VEHICLE = gql`
  query dealsForVehicle($vehicleId: ID!) {
    deals(where: { vehicles_every: { id: $vehicleId } }) {
      __typename
      ...DealFragment
    }
  }
  ${DealFragment}
`
// query.ts

import gql from "graphql-tag"
import { DealFragment} from "./dealFragment"

const DEALS_FOR_VEHICLE = gql`
  query dealsForVehicle($vehicleId: ID!) {
    deals(where: { vehicles_every: { id: $vehicleId } }) {
      __typename
      ...DealFragment
    }
  }
  ${DealFragment}
`

// dealFragment.ts
import gql from "graphql-tag"

export const DealFragment = gql`
  fragment DealFragment on Deal {
    id
  }
`

Returns

$ graphql-codegen --config codegen.yml
  ✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate src/generated/graphql.tsx
      ✔ Load GraphQL schemas
      ✔ Load GraphQL documents
      ✖ Generate
        → Cannot read property 'onType' of undefined


 Found 1 error

  ✖ src/generated/graphql.tsx
    TypeError: Cannot read property 'onType' of undefined

codegen.yml

overwrite: true
schema: "../admin-server-nexus/src/generated/schema.graphql"
documents:
  - "src/containers/deals/**/*.tsx"
  - "src/containers/queries/**/*.tsx"
generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"

Thanks for the amazing work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

21. Sentence Errors: Fragments and Run-Ons
Run-on sentence consist of multiple complete sentences that have been incorrectly joined or not properly separated. There are two types of run-on sentences: ......
Read more >
android - Fragments within Fragments - Stack Overflow
This is caused because the the container for FragmentNumber3 has been duplicated and it no longer has a unique ID. The initial Fragment...
Read more >
Sources of Error in Gel Electrophoresis - Sciencing
This method involves the migration of fragments of DNA through a gel, where they are separated on the basis of size or shape....
Read more >
Fragment transactions - Android Developers
The FragmentTransaction method detach() detaches the fragment from the UI, destroying its view hierarchy. The fragment remains in the same state ...
Read more >
Comma Splices and Run-On Sentences - Research Guides
The following are very common mistakes related to punctuation usage (or lack of usage) ... and you need something a little stronger to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found