kadirahq/lokka

How can i use fragments recursively?

Closed this issue · 2 comments

Hi! I want to use fragment recurcively...

    export const folderFragment = client.createFragment(`
        fragment on Folder {
            id
            name
            description
            shortdescription
            image
            folders {
                ...${folderFragment}
            }
        }
    `);
    client.query(`{
        folders {
            ...${folderFragment}
        }
    }`);

but i get an error

error Error: There is no such fragment: undefined

Help me please..Thank you!

little hack with

    gql._fragments.folderFragment = gql._fragments[folderFragment];
   ...${folderFragment} -> ...folderFragment

doesn't work. I get an error:

error RangeError: Maximum call stack size exceeded

but i can run query in graphiql gui on Golang GraphQL server (https://github.com/neelance/graphql-go/) with no errors

fragment folderFragment on Folder {
  id
  name
  description
  shortdescription
  image
  folders {
    ...folderFragment
  }
}
query {
  folders {
    ...folderFragment
  }
}

Please, check my pull request #35