fauna-labs / fauna-schema-migrate

The Fauna Schema Migrate tool helps you set up Fauna resources as code and perform schema migrations.
MIT No Attribution
88 stars 11 forks source link

Erroneous undefined reference errors #78

Closed rachaelmcq closed 3 years ago

rachaelmcq commented 3 years ago

When I try to generate migrations, I get errors claiming the resources "[aren't] defined anywhere in the resource folders". For the following fauna/resources/functions.fql:

CreateFunction({
  name: "A",
  role: "server",
  body: Query(
    Lambda(
      "",
      true
    )
  )
})
CreateFunction({
  name: "B",
  role: "server",
  body: Query(
    Lambda(
      "",
      Call(Function("A"), []),
    )
  )
})

I get the error:

! Error:
      The following resource is not defined anywhere in the resource folders
          type: Function, name: A
      and was referenced from:
          type: Function, name: B

However, if I swap the order I declare these functions in:

CreateFunction({
  name: "B",
  role: "server",
  body: Query(
    Lambda(
      "",
      Call(Function("A"), []),
    )
  )
})
CreateFunction({
  name: "A",
  role: "server",
  body: Query(
    Lambda(
      "",
      true
    )
  )
})

I have no problems. This is true of every resource I'm creating that references another resource, and across files as well. Depending on defining them in reverse order and then having the error say depended-on resources aren't "anywhere in the resource folders" is pretty confusing.

rachaelmcq commented 3 years ago

Seems like the workaround here might be to define every resource in its own file.

databrecht commented 3 years ago

Hey @rachaelmcq, it's not really a workaround, it's intended to work like that. It expects that only one resource is defined in each file. Since you bumped into this ideally it should warn about this when there are multiple resources defined, or it should be allowed to define multiple resources in a file.

rachaelmcq commented 3 years ago

Ah, I missed that. Yeah, a warning about multiple resources in one file would help.