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

Improvements #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Improvements #1

wants to merge 2 commits into from

Conversation

OlegIlyenko
Copy link

  • Collected all type-class instances of model classes in companion objects
  • Using fetch API to efficiently load model and its relations
  • Added a test
  • Other minor refactorings
  • Updated dependencies

* Collected all type-class instances of model classes in companion objects
* Using fetch API to efficiently load model and its relations
* Added a test
* Other minor refactorings
* Updated dependencies
<link rel="stylesheet" href="//cdn.jsdelivr.net/graphiql/0.8.0/graphiql.css" />
<script src="//cdn.jsdelivr.net/graphiql/0.8.0/graphiql.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/graphiql/0.9.3/graphiql.css" />
<script src="//cdn.jsdelivr.net/graphiql/0.9.3/graphiql.min.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the rest of the HTML need to be updated as well or just the JS/CSS?

As a side note, I'll probably end up embedding these files in the repo instead of relying on a CDN in case I lose Internet connection during the live demo 😅.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the rest should work just fine with the new version of GraphiQL

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, done in 762db15. Thanks!

@@ -0,0 +1 @@
sbt.version=0.13.13
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very much unaware of Scala tooling as I'm a complete beginner. Any specific reason why you added this + the .idea in the .gitignore file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sbt.version locks down the SBT version. If you don't have this defines, SBT launcher will take whatever is installed in your system and it is quite unreliable. I, for instance, haven't updated SBT setup for a long time and project failed to start because of this. build.properties fixed it.

.idea folder is just an intellij idea project files. You don't really want them in a git repo, so i ignored them :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re:  sbt.version, gotcha, added in 4bfd1d2.

Re: .idea, I prefer to keep OS-specific and IDE-specific files out of my projects and use a global ignore list instead. For example, see this and that. That's a personal preference but I prefer that over having to duplicate/maintain these in all project gitignore files :)

name: String)

object Category {
implicit val categoryHasId = HasId[Category, Int](_.id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see HasId lives here, do you mind explaining what it's for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasId is a type-class needed for Fetch API to be able to cache and handle entities. It just provides an evidence/knowledge how to get an ID from your domain object (Category in this case)

implicit val graphqlType: ObjectType[Repository, Category] = deriveObjectType(
ObjectTypeDescription("A category"),
AddFields(Field("styles", ListType(Style.graphqlType),
resolve = c => c.ctx.styleFetcher.deferRelSeq(c.ctx.styleByCategory, c.value.id))))
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep my models GraphQL-free, separating layers sort of, so that case classes contain the business logic and the schema file focuses on the GraphQL integration. Was that a stupid idea?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The domain models in this case still completely unaware of JSON serialization or GraphQL. I guess it's just very convenient way to pack all type-class instances for particular case class in its companion object. They are indeed co-located in a single file, but from application's perspective, they are sill loosely coupled.

val styles = styleSource.convertTo[List[Style]]
private def loadFile[T : JsonFormat](fileName: String): List[T] =
io.Source.fromResource(fileName)("UTF-8").mkString.parseJson.convertTo[List[T]]
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I did try exactly that but I got confused with the required implicit definition of jsonFormatN, brilliant!

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

Successfully merging this pull request may close these issues.

2 participants