0

When using the graphql-tools JsonFileLoader with the follow schema.json:

{
  "UserObjectType": {
    "id": "Int",
    "username": "String",
    "firstName": "String",
    "lastName": "String",
    "avatar": "AvatarObjectType",
    "dateCreated": "DateTime",
    "notificationPreferences": "GenericScalar"
  },
  "AvatarObjectType": { "id": "Int", "avatarUrl": "String" },
  "scalar": ["DateTime", "GenericScalar"],
  "Query": {
    "GetCurrentUser": "UserObjectType"
  }
}

I get the following error:

Unable to find any GraphQL type definitions for the following pointers:
            
              - UserObjectType
              ,
              - AvatarObjectType
              ,
              - scalar
              ,
              - Query

                
      at prepareResult (dist/load/src/load-typedefs.js:70:15)
      at loadTypedefs (dist/load/src/load-typedefs.js:35:12)

Here's my code:

const JSONSchema = await loadSchema(schema, {
      loaders: [new JsonFileLoader()],
    });

    const mocks = {
      String: () => "abc",
      Int: () => 56,
      UserObjectType: () => ({
        firstName: "John",
        lastName: "Smith",
      }),
    };

    // Create a new schema with mocks
    const schemaWithMocks = addMocksToSchema({
      schema: JSONSchema,
      mocks,
    });

Reproduction repo is here and more specifically, the test where I use JSONFileLoader is here.

EDIT: I used @graphql-codegen/cli's introspection plugin to generate a new JSON which you can find here.

When loading this into my test, I get a similar error:

graphql-tools › Runs mocked Schema with JsonFileLoader


          Unable to find any GraphQL type definitions for the following pointers:
            
              - __schema

                
      at prepareResult (dist/load/src/load-typedefs.js:70:15)
      at loadTypedefs (dist/load/src/load-typedefs.js:35:12)
Fredmental
  • 445
  • 1
  • 7
  • 14
  • why do you think json should be formatted this way? – xadm Apr 08 '21 at 18:48
  • My thought processes was that I was just converting a schema string I've used successfully into a .json file. You can see an example of that here where I use the same schema but in a schema string that has a working test for it. https://github.com/Freddie-Pike/graphql_tools_workings/blob/main/example_test/graphql-tools-mergeResolvers.test.js If there's a "correct" way to format the json, I'm all ears! – Fredmental Apr 08 '21 at 19:11
  • and 'type' converted to what property? ... I'd check https://www.graphql-code-generator.com/ and `Introspection JSON` option – xadm Apr 08 '21 at 20:22
  • I guess you didn't tested `schema: JSONSchema.__schema,` ? – xadm Apr 09 '21 at 14:21
  • @xadm just tested that. The error occurs on this line so `JSONSchema.__schema` won't work `const JSONSchema = await loadSchema(schema.__schema, { loaders: [new JsonFileLoader()], });` I've tried passing `schema.__schema` to `loadSchema` but I get this error: `Unable to find any GraphQL type definitions for the following pointers: - queryType, - mutationType, - subscriptionType, - types, - directives` – Fredmental Apr 09 '21 at 15:25
  • I thought about `addMocksToSchema({ schema: JSONSchema.__schema,` – xadm Apr 09 '21 at 15:41
  • @xadm I get that, but that doesn't work because the test fails at the `loadSchema` because the JSON schema isn't in the correct format and can't find any GraphQL type definitions when passing `schema` into `new JsonFileLoader`. – Fredmental Apr 09 '21 at 16:20
  • check json file without `__schema` level/object? – xadm Apr 09 '21 at 16:30

0 Answers0