Skip to content

makeSafeQueryRunner type error #360

Open
@cjcartier

Description

@cjcartier

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Code Sandbox link

No response

Bug report

This is probably me and might not be a bug. 

I created the `runQuery` as so: 


export const runQuery = makeSafeQueryRunner((query, params: Record<string, unknown> = {}) =>
  client.fetch(query, params),
);


But when I use it as typed: 


const pageData = (await runQuery(pageQuery, { parameters: { slug } }))[0]


I get the following error: 

`[ Server ] Error: param $slug referenced, but not provided`

Here is the query I have written: 


const pageQuery = q
    .parameters<{ slug: string }>()
    .star.filterByType('page')
    .filterBy('seo.slug.current == $slug')
    .project(page => ({
      body: page.field('body[]').project(componentGeneratorFragment),
    })),

However if I were to change the `runQuery` like so: 


const pageData = (await runQuery(pageQuery, { slug }))[0];


It retrieves the data fine but I am getting the type error 


Argument of type '{ slug: string; }' is not assignable to parameter of type '{ parameters: { slug: string; }; } & Record<string, unknown>'.
  Property 'parameters' is missing in type '{ slug: string; }' but required in type '{ parameters: { slug: string; }; }'


It seems that the typing of `makeSafeQueryRunner` might not actually line up with the function? Or maybe I set something up wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgroqd-v1Related to the newer `v1.x` packagemigration-to-v1Help for migrating from v0.x to v1.x

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions