Skip to content

"Error calling module function" with gql tagged template literals #1284

@darkbasic

Description

@darkbasic

https://github.com/darkbasic/nativescript-repro1/blob/master/app/item/item.service.ts

const taggedTemplateLiteralDoesNotWorkHere = gql`
  query GetChats($amount: Int) {
    chats {
      id
      messages(amount: $amount) {
        id
      }
    }
  }
`;

gql tagged template literals don't work in Nativescript, unless you put them inside a class:

@Injectable()
export class ItemService {
    theSameTaggedTemplateLiteralWorksHere = gql`
      query GetChats($amount: Int) {
        chats {
          id
          messages(amount: $amount) {
            id
          }
        }
      }
    `;
}

If I use gql as a function instead of a tagged template literal it works fine everywhere:

const callingItAsFunctionWorksFine = gql(`
  query GetChats($amount: Int) {
    chats {
      id
      messages(amount: $amount) {
        id
      }
    }
  }
`);

3

Full Error: http://paste.ubuntu.com/p/SMKyCvGkdW/

I thought it could have been an issue with Typescript's cache (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html), but I get the same issue with Typescript 2.6, 2.6 and 2.7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions