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

API.swift generated class is empty #13

Closed
stephensilber opened this issue Oct 28, 2016 · 13 comments
Closed

API.swift generated class is empty #13

stephensilber opened this issue Oct 28, 2016 · 13 comments

Comments

@stephensilber
Copy link

I have followed the steps on the installation page and have a compiling project. I have also imported the proper schema.json from my server, but the script seems to generate a blank API.swift file. Am I missing something here?

I am using Cocoapods to install the latest version (0.3.1 I believe), and have installed apollo-codegen from npm. Any help would be appreciated!

@martijnwalraven
Copy link
Contributor

Hmmm, do you have any queries defined yet in .graphql files? Because Apollo iOS creates query-specific result types, it needs queries to generate code from.

If you have written some queries, where are your .graphql files located? They'll have to be stored inside the project directory (or you would have to change the apollo-codegen invocation in the run script build step).

@stephensilber
Copy link
Author

yep, that looks like the problem. Just had the question answered on slack. Thanks for the quick response! Really looking forward to the future of this library 😄

@Naoto-Ida
Copy link

I'm still getting an empty API.swift. I've checked out the Slack channel by the way.

My .graphql as well as the schema.json file resides in a folder called data right under my project folder.
So I modified $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') --schema schema.json --output API.swift with $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') --schema data/schema.json --output API.swift

My schema has been used a few days ago in my React Native/Relay app, so I'm pretty sure my .graphql is standard. Any possible solutions?

@martijnwalraven
Copy link
Contributor

martijnwalraven commented Dec 2, 2016

So just to make sure, your .graphql files contain queries?

Are there any error messages when you build your target?

If you've copied the default build script, it expects both your schema.json and the .graphql files in the target directory:

cd ${SRCROOT}/${TARGET_NAME}

So if you've put them in the parent project directory instead, that may be the issue. But I would have expected an error message in that case.

@Naoto-Ida
Copy link

Naoto-Ida commented Dec 2, 2016

Sorry, I haven't been doing iOS dev for about a year, so its a bit rusty.
So I've gotten rid of that data directory I've mentioned above.

My target directory is called MusicApp, and the actual directory structure is like this:

MusicApp
  -> API.swift
  -> AppDelegate.swift
  -> schema.graphql
  -> schema.json
Pods

I haven't got any errors when building and running the script as is which I got from the docs.

My schema contains stuff like:

schema {
  query: RootQueryType
}

enum AlbumType {
  SINGLE
  EP
  ALBUM
  MAXI_ALBUM
  PROMO
}

type ArticleConnection {
  pageInfo: PageInfo!
  edges: [ArticleEdge]
  count: Int
}

etc.

@martijnwalraven
Copy link
Contributor

That looks good, except for the schema.graphql. The schema should be in schema.json, and .graphql files are then used to define queries and mutations that use the schema.

apollo-codegen generates query-specific types, that only contain the fields you actually query for. So without any queries, API.swift will indeed be empty.

You may want to take a look at the FrontPage example app.

@Naoto-Ida
Copy link

Ah, OK, that example app helped me out a lot. Thank you 🖖. I didn't quite understand what it meant by *.graphql since my GraphQL outputs a schema.json and schema.graphql by default whenever I push a release.

So if there is a SoundtrackViewController.swift there should be a SoundtrackViewController.graphql in the target project directory, correct?

@martijnwalraven
Copy link
Contributor

You can organize your .graphql files any way you want, and they will all be processed together. But it is a best practice to keep your queries together with the components that use them.

An added benefit of that is that we also have an Xcode integration that shows you the corresponding .graphql file for a Swift file in a companion view so you can edit them side by side. See the short screen recording at the end of this blog post for an example.

@KGDhingra
Copy link

I have written some query in my .graphql file but still my API.swift is empty ..can anyone help?

@KGDhingra
Copy link

I solved my problem. Actually my .graphql file was outside of project directory hence API.swift file was empty.

@Angelzzz
Copy link

Angelzzz commented Nov 9, 2018

I didn't get the solution ....Anyone please help me

@vincekinyops
Copy link

hi guys, new to apollo-ios, i still cant generate code in my API.swift, my .graphql file and schema.json are already under my project folder, any other suggestions as to this issue?

@umairhassanbaig
Copy link

In some cases if the syntax of queries/mutations is incorrect, you don't get any error on compile time but an empty API.swift file. Make sure that your syntax is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants