Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo-vscode: Cannot use local schema file #669

Closed
stnwk opened this issue Nov 8, 2018 · 12 comments · Fixed by #676
Closed

apollo-vscode: Cannot use local schema file #669

stnwk opened this issue Nov 8, 2018 · 12 comments · Fixed by #676

Comments

@stnwk
Copy link
Contributor

stnwk commented Nov 8, 2018

Hi everyone!

I was just trying to figure out how to configure the new VSCode Extension, but I simply couldn't manage to do so.

That's my situation:

  • installed apollo 2.0.5 - reloaded everything
  • not using Apollo Engine
  • cannot use an actual api endpoint (because of auth)
  • local schema file available in JSON
  • All my graphql files are under src/**

How do I successfully configure this in my apollo.config.js? I've tried everything but somehow it never works.

module.exports = {
  service: {
    localSchemaFile: './internals/schema.graphql',
  },
};

^ This config does not output anything in the debug view.

module.exports = {
  client: {
    service: {
      localSchemaFile: './internals/schema.graphql',
    },
  }
};

^ This config outputs TypeError: Only absolute URLs are supported - welp

Additionally I receive the following error although I don't wan't to use the Apollo Engine related stuff..
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Unable to find ENGINE_API_KEY

Can someone help me? The docs weren't really helpful about this :(

Might be related to #667 ?

@jessedvrs
Copy link

When I take a look at this source code here:

Looks like the endpoint configuration option is set by default. That may be causing your TypeError. Can you try to change your config to:

module.exports = {
  client: {
    service: {
      localSchemaFile: './internals/schema.graphql',
      endpoint: null
    },
    includes: [
      "client/src/**/*.{ts,tsx,js,jsx,graphql}"
    ]
  }
};

Replace client/src with the path to your source code. This setting defaults to src/**/*.{ts,tsx,js,jsx,graphql}.

Also, apollo.config.js must be located in your project root (as seen by vscode).

@jpaas
Copy link

jpaas commented Nov 8, 2018

Same problem here. I tried it with endpoint: null but same result

@stnwk
Copy link
Contributor Author

stnwk commented Nov 8, 2018

@jpaas @jessedvrs I did a little more digging into the whole codebase and determined it is definitely a bug.

Came up with a PR #676 to solve this :)

@gund
Copy link

gund commented Mar 4, 2019

EDIT: Never mind, it was fixed after VScode restart...

@stnwk this error still happens for me!

My config:

module.exports = {
  client: {
    service: {
      name: 'MYGQL',
      localSchemaFile: './src/generated/graphql.schema.json',
      includes: ['src/**/*.{graphql,ts,js}'],
      excludes: ['**/node_modules/**'],
    },
  },
};

Error: Error in "Loading schema for MCQL": TypeError: Only absolute URLs are supported

I'm using latest VSCode plugin Apollo GraphQL

@ktsosno
Copy link

ktsosno commented Mar 7, 2019

Had the same problem, needed to fully restart VSCode after editing the apollo.config.js. Adding endpoint: null had no effect.

My config:

module.exports = {
  client: {
    service: {
      name: 'consumer-app',
      localSchemaFile: './schema.graphql'
    },
    includes: ['src/**/*.gql', 'src/**/*.ts', 'src/**/*.tsx']
  }
}

@JakeDawkins
Copy link
Contributor

@ktsosno are you saying you're still having this problem after a restart?

You shouldn't have needed to restart vscode after a config change. That should've been fixed a while back. Can you make sure you're up to date on the extension if so?

@kazinad
Copy link

kazinad commented Apr 18, 2019

  1. According to my experience, restarting VSCode is still a requirement, Apollo extension notices the saving of the apollo.config.js file, but it tries to load the previous config.
  2. I could not ever configure Apollo extension properly, i tried the the above include workaround without luck, but the docs say include is not necessary at all, so I removed it:
module.exports = {
  client: {
    service: {
      name: 'server-app',
      localSchemaFile: '../../server-app/src/GraphQL/schema.graphql'
    }
  }
};

I use this config file in a multi root workspace, and I definitely sure, the file path is correct, but still got this error:


🚀 Apollo GraphQL v1.5.2

❌ Service stats could not be loaded. This may be because you're missing an apollo.config.js file or it is misconfigured. For more information about configuring Apollo projects, see the guide here (https://bit.ly/2ByILPj).

  1. The error message is displayed only if a file is open. You can't see the error message if there is no open file

@aaronmcadam
Copy link

@kazinad I can confirm using a local schema doesn't work for me within workspaces, but does work when I run a project on its own.

@tomsseisums
Copy link

tomsseisums commented Nov 8, 2019

@aaronmcadam that should be possible to quick-fix via constructing path programmatically with __dirname:

module.exports = {
  client: {
    service: {
      name: 'server-app',
      localSchemaFile: path.resolve(__dirname, '<path to schema>')
    }
  }
}

This works, because __dirname will resolve to the directory where the actual file resides. No matter what working directory you execute it from.

@aaronmcadam
Copy link

Thanks for this @joltmode, but I now use graphql-codegen for this tooling instead.

This makes sense though, I think this might be useful for other tools inside workspaces, thanks!

@kaushal-aubie
Copy link

module.exports = {
  client: {
    name: 'graphql-vscode-client-test',
    service: {
      localSchemaFile: 'schema.graphql',
    },
  },
};

This config is working for me
my schema.graphql is schema file at root level

@trevor-scheer
Copy link
Member

@kaushal-aubie thank you for sharing what's working for you, but this issue is closed and over 3 years old. Please use good judgement when commenting on issues. Everyone on this thread receives an (almost certainly) unwanted notification.

@apollographql apollographql locked and limited conversation to collaborators Jul 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.