Giter Site home page Giter Site logo

Comments (13)

martijnwalraven avatar martijnwalraven commented on July 23, 2024 1

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.

from apollo-ios.

martijnwalraven avatar martijnwalraven commented on July 23, 2024 1

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.

from apollo-ios.

KGDhingra avatar KGDhingra commented on July 23, 2024 1

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

from apollo-ios.

martijnwalraven avatar martijnwalraven commented on July 23, 2024

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).

from apollo-ios.

stephensilber avatar stephensilber commented on July 23, 2024

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 😄

from apollo-ios.

Naoto-Ida avatar Naoto-Ida commented on July 23, 2024

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?

from apollo-ios.

martijnwalraven avatar martijnwalraven commented on July 23, 2024

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.

from apollo-ios.

Naoto-Ida avatar Naoto-Ida commented on July 23, 2024

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.

from apollo-ios.

Naoto-Ida avatar Naoto-Ida commented on July 23, 2024

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?

from apollo-ios.

KGDhingra avatar KGDhingra commented on July 23, 2024

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

from apollo-ios.

Angelzzz avatar Angelzzz commented on July 23, 2024

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

from apollo-ios.

vincekinyops avatar vincekinyops commented on July 23, 2024

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?

from apollo-ios.

umairhassanbaig avatar umairhassanbaig commented on July 23, 2024

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.

from apollo-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.