What is the best way to achieve the following data...
# orm-help
d
What is the best way to achieve the following datamodel.graphql
Copy code
graphql
type File {
  id: ID! @unique
  path: String!
}
schema.graphql
Copy code
graphql
# import File from "./generated/prisma.graphql"

// I want to extend the application schema to load the file and convert to base64, but don't want to keep in database.
Is this possible?
extend type File {
  base64: String
}

or inherit
type ExtendedFile inherits File {
  base64: String
}
Do I redefine all the File fields in the schema graphql?
v
d
So you added that to the Prisma project. I thought Prisma was already using stitching. I’ll dig farther into the cose
n
@dreadjr @dreadjr a change to
schema.graphql
does not affect
datamodel.graphql
d
@nilan I am looking to have “computed” fields in the
schema.graphql
that aren’t in the underlying database
datamodel.graphql
. I think i have achieved this through something like this, Also just redefined
File
in the
schema.graphql
with the extra field instead of importing it.
Copy code
js
base64: {
    fragment: `fragment Base64 on File { id path }`,
    resolve: async ({ path, base64 }, args, ctx, info) => {
      if (base64) {
        // console.log("already have it base64", parent);
        return base64;
      }

      console.log("getting base64", path);
      return await fileToString(path, 'base64');
    }
  },
Do you think this is a good way to achieve this?
n
That's great, I'd do it the same 🙂
fragment:
fragment Base64 on File { id path }
,
it doesn't look like you'd need
id
though, you are not using it anywhere
hmm actually I don't see why you need
fragment
at all, you are not using that
path
either
d
It was really just to stop a warning/ error when I would do a query since it is nested under a parent node. There problem is a much better solution.