Hello! - I am working on a workflow for server / s...
# prisma-whats-new
l
Hello! - I am working on a workflow for server / schema development. I have setup and am using the graphql-import tool to form my schema. We are using TypeScript and the next step would be to create types / interfaces to support resolver development with static types from the schema. I seem to be missing this step. I realize I can generate a schema / json file from a running instance of my service but wondering if there is a way to do this from my same
schema.graphql
that currently just has imports from a number of other
.graphql
files. Also I am noticing that the codegen pieces also need to inspect my
.graphql
files which currently require introspection from
graphql-import
as they contain imports. I feel like I am missing a piece here that bridges the codegen to complete the creation of TypeScript types.
1
a
If you are using
.graphqlconfig
to specify your configuration, you can use the
graphql prepare
step to both process your schema imports, and generate static bindings
l
Thanks for the response. Any thoughts on this error?
Copy code
graphql prepare --bundle --bindings -o generated -s -p dr-api
✖ Processing schema imports for project dr-api...
Syntax Error: Unexpected <EOF>
Copy code
➜  dr-api git:(master) ✗ tree src          
src
├── index.ts
├── schema.graphql
├── schema.ts
├── transformation
│   ├── imageObjectDetection
│   │   ├── resolvers.ts
│   │   └── schema.graphql
│   ├── resolvers.ts
│   └── schema.graphql
└── utils
    ├── ArgsMapper.ts
    ├── DynamoList.ts
    ├── db.ts
    └── typeTools.ts
Copy code
{
  "projects": {
    "dr-api": {
      "schemaPath": "src/schema.graphql",
      "extensions": {
        "endpoints": {
          "dev": "<http://localhost:4001/graphql>"
        }
      }
    }
  }
}
schema.graphql
Copy code
# import * from "transformation/schema.graphql"
# import * from "transformation/imageObjectDetection/schema.graphql"
The server runs without issue currently using:
Copy code
import { importSchema } from "graphql-import";
import { makeExecutableSchema } from "graphql-tools";

import { TransformationResolver } from "./transformation/resolvers";
import { ImageObjectDetectionResolver } from "./transformation/imageObjectDetection/resolvers";

const typeDefs = importSchema("src/schema.graphql");

console.log(typeDefs);

const resolvers = {
  ...TransformationResolver,
  ...ImageObjectDetectionResolver
};

const schema = makeExecutableSchema({ typeDefs, resolvers });
export default schema;
a
Which version of
graphql-cli
are you using?
Ah, I found it. The current version of
graphql-cli
doesn't support empty schemas yet
Could you add a
type Dummy { dummy: String }
to your
schema.graphql
to make sure that is the issue?
l
sure
looks like that worked! Thanks! I also added
-g bindings-ts
a
Okay, give me a sec...
Okay, I have just released a new version of
graphql-cli
(v2.12.5), so if you can install that one globally, it should support an empty root schema
l
awesome - I will pull it down and test now
👍🏻 1
Perfect - worked great. Thanks again!@!
a
You're welcome, it was a feature that was released in one of the upstream packages a while ago, but not updated all the way to
graphql-cli
...