Skip to content

fmodata: Nested expand generates empty $select= causing OData parse error #109

@eluce2

Description

@eluce2

Description

When using nested expand() calls without explicit select(), the library generates an empty $select= statement which FileMaker OData cannot parse.

Reproduction

import { fmTableOccurrence, textField, containerField, FMServerConnection } from "@proofkit/fmodata";

const Parent = fmTableOccurrence("Parent", {
  _pk: textField().primaryKey().entityId("FMFID:1"),
}, {
  entityId: "FMTID:1",
  navigationPaths: ["Child"],
});

const Child = fmTableOccurrence("Child", {
  _pk: textField().primaryKey().entityId("FMFID:2"),
  data: textField().entityId("FMFID:3"),
}, {
  entityId: "FMTID:2",
  navigationPaths: ["Parent"],
});

const connection = new FMServerConnection({
  serverUrl: "https://example.com",
  auth: { username: "test", password: "test" },
});

const db = connection.database("Test.fmp12", { useEntityIds: true });

// This generates invalid URL
const query = db
  .from(Parent)
  .get("test-id")
  .expand(Child);

console.log(query.getQueryString());
// Output: /FMTID:1('test-id')?$select=FMFID:1&$expand=FMTID:2($select=)
//                                                              ^^^^^^^^^ empty select

Expected behavior

Either:

  1. Omit $select= entirely when no fields are selected
  2. Or include all fields by default

Actual behavior

Generates $select=) which causes FileMaker OData to return:

OData error: Error: parse failure in URL at: ')'

Workaround

Explicitly call .select() with at least one field on every expand:

const query = db
  .from(Parent)
  .get("test-id")
  .expand(Child, (b) => b.select({ data: Child.data }));

Environment

  • @proofkit/fmodata version: 0.1.0-beta.24
  • FileMaker Server OData API

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