#Custom GraphQL query nested field returns null

1 messages · Page 1 of 1 (latest)

rugged island
#

Hi, I have a custom GraphQL query to grab a Page by its slug. A Page contains a relation towards meta and an array called content.

If I try to access the anything within the meta relation, it always gives me null . It works for the content though. And if I log the result in the console, I do see meta as an Object

I've tried adding access.read to be () => true everywhere to see if it would affect it to no avail. Putting depth also on the query did not work :<

GQL query (in playground):

{
  PageBySlug(slug: "blog") {
    id
    content {
      ... on ComponentPageMargin {
        __typename
        height
      }
      ... on ComponentPageBlockCardHeader {
        __typename
        title
        description
        id
        blockName
      }
    }
    meta {
      id
    }
  }
}

Custom query:

// src/queries/pageBySlug.ts
type GraphQL =
  typeof import("/home/rayhanw/code/rayhanw/learn/blog/apple/node_modules/graphql/index");
type PageBySlug = (
  graphQL: GraphQL,
  payload: Payload
) => Record<string, unknown>;

const resolve = async (
  _: unknown,
  args: {
    slug: string;
  },
  ctx: {
    req: PayloadRequest;
    res: Response;
  }
) => {
  const { payload } = ctx.req;
  const options: Options = {
    collection: "pages",
    depth: 10,
    where: {
      slug: { equals: args.slug },
    },
    limit: 1,
  };
  const result = await (payload as Payload).find(options);
  console.dir(result.docs[0]);

  return result.docs[0];
};

const PageBySlug: PageBySlug = (graphQL, payload) => {
  return {
    type: payload.Query.fields.Page.type,
    args: {
      slug: { type: graphQL.GraphQLString },
    },
    depth: 10,
    resolve,
  };
};

export default PageBySlug;

// payload.config.ts
export default buildConfig({
  // [...]
  queries(GraphQL, payload) {
    return {
      PageBySlug: PageBySlug(GraphQL, payload),
    };
  },
  // [...]
})

Thank you!

rustic wharf
#

@rugged island do you still need help with this issue? if so, could you log the result again and share here?